Problem with graphql executeAutomationCommand and notifyEvent mutations on v5.3.2

I’m using 5.3.2 and trying to Execute Automation Command via graphql to update an entity, however I am getting an error message when testing that makes no sense. First tried using executeAutomationCommand

GraphQL:

mutation m{executeAutomationCommand(
  name:"Update Customer",
  parameters:[
    {name:"EntityName", value:"1234"},
    {name:"FirstName", value:"Mark"},
    {name:"LastName", value:"Wallace"},
    {name:"Street", value:"123 Any Street"},
    {name:"Town", value:"Anytown"},
    {name:"PostCode", value:"AA1 1AA"},
    {name:"Email", value:"test@example.com"}
  ],
  user:"Admin",
  ticketType:"Delivery",
  terminal:"Server",
  department:"Delivery / Collection"
)}

Response:

{
  "data": {
    "executeAutomationCommand": null
  },
  "errors": [
    {
      "locations": [
        {
          "line": 0,
          "column": 0
        }
      ],
      "message": "Error trying to resolve executeAutomationCommand.",
      "data": {},
      "innerException": {
        "ClassName": "System.MissingMethodException",
        "Message": "No parameterless constructor defined for this object.",
        "Data": null,
        "InnerException": null,
        "HelpURL": null,
        "StackTraceString": "   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)\r\n   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)\r\n   at System.Activator.CreateInstance(Type type, Boolean nonPublic)\r\n   at System.Activator.CreateInstance(Type type)\r\n   at GraphQL.ObjectExtensions.ToObject(IDictionary`2 source, Type type)\r\n   at GraphQL.ObjectExtensions.GetPropertyValue(Object propertyValue, Type fieldType)\r\n   at GraphQL.ObjectExtensions.GetPropertyValue[T](Object value)\r\n   at GraphQL.Types.ResolveFieldContext.Argument[TType](String name)\r\n   at Samba.Services.Graphql.Automation.NotifyEventMutation.<.ctor>b__6_0(ResolveFieldContext context) in C:\\Users\\Vehbi\\Documents\\Source\\Repos\\sambapos-v5-pro\\Samba.Services\\Graphql\\Automation\\NotifyEventMutation.cs:line 112\r\n   at GraphQL.DocumentExecuter.<ResolveFieldAsync>d__8.MoveNext()",
        "RemoteStackTraceString": null,
        "RemoteStackIndex": 0,
        "ExceptionMethod": "8\nCreateInstance\nmscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\nSystem.RuntimeTypeHandle\nSystem.Object CreateInstance(System.RuntimeType, Boolean, Boolean, Boolean ByRef, System.RuntimeMethodHandleInternal ByRef, Boolean ByRef)",
        "HResult": -2146233069,
        "Source": "mscorlib",
        "WatsonBuckets": null,
        "MMClassName": null,
        "MMMemberName": null,
        "MMSignature": null
      },
      "stackTrace": null,
      "helpLink": null,
      "source": null,
      "hResult": -2146233088
    }
  ]
}

When this didn’t work, I tried using notifyEvent as described here…

…but I get a similar error when running that as well…

GraphQL:

mutation m{notifyEvent(
  event:"AutomationCommandExecuted",
  parameters:[
    {name:"AutomationCommandName",value:"Update Customer"},
    {name:"EntityName", value:"1234"},
    {name:"FirstName", value:"Mark"},
    {name:"LastName", value:"Wallace"},
    {name:"Street", value:"123 Any Street"},
    {name:"Town", value:"Anytown"},
    {name:"PostCode", value:"AA1 1AA"},
    {name:"Email", value:"test@example.com"}
  ],
  user:"Admin",
  ticketType:"Delivery",
  terminal:"Server",
  department:"Delivery / Collection",
  state:{ticket:{id:0}}
){ticket{id}}}

Response:

{
  "data": {
    "notifyEvent": null
  },
  "errors": [
    {
      "locations": [
        {
          "line": 0,
          "column": 0
        }
      ],
      "message": "Error trying to resolve notifyEvent.",
      "data": {},
      "innerException": {
        "ClassName": "System.MissingMethodException",
        "Message": "No parameterless constructor defined for this object.",
        "Data": null,
        "InnerException": null,
        "HelpURL": null,
        "StackTraceString": "   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)\r\n   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)\r\n   at System.Activator.CreateInstance(Type type, Boolean nonPublic)\r\n   at System.Activator.CreateInstance(Type type)\r\n   at GraphQL.ObjectExtensions.ToObject(IDictionary`2 source, Type type)\r\n   at GraphQL.ObjectExtensions.GetPropertyValue(Object propertyValue, Type fieldType)\r\n   at GraphQL.ObjectExtensions.GetPropertyValue[T](Object value)\r\n   at GraphQL.Types.ResolveFieldContext.Argument[TType](String name)\r\n   at Samba.Services.Graphql.Automation.NotifyEventMutation.<.ctor>b__6_1(ResolveFieldContext context) in C:\\Users\\Vehbi\\Documents\\Source\\Repos\\sambapos-v5-pro\\Samba.Services\\Graphql\\Automation\\NotifyEventMutation.cs:line 152\r\n   at GraphQL.DocumentExecuter.<ResolveFieldAsync>d__8.MoveNext()",
        "RemoteStackTraceString": null,
        "RemoteStackIndex": 0,
        "ExceptionMethod": "8\nCreateInstance\nmscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\nSystem.RuntimeTypeHandle\nSystem.Object CreateInstance(System.RuntimeType, Boolean, Boolean, Boolean ByRef, System.RuntimeMethodHandleInternal ByRef, Boolean ByRef)",
        "HResult": -2146233069,
        "Source": "mscorlib",
        "WatsonBuckets": null,
        "MMClassName": null,
        "MMMemberName": null,
        "MMSignature": null
      },
      "stackTrace": null,
      "helpLink": null,
      "source": null,
      "hResult": -2146233088
    }
  ]
}

I have the rule and action setup as follows:

image
image

image

Before doing all this, I have also tried using the updateEntityCustomData mutation to update the entity custom data directly from GraphQL, however there appears to be a bug with that mutation that only updates the entity randomly, hence why I’m trying the above ways.

1 Like

I just did a quick test on 5.3.0 and it is working fine, so this appears to be an issue in 5.3.2.

On 5.3.0:

I also confirmed on another system with a different database in 5.3.2 and it gives the same error message.

1 Like

Sounds like an old DLL got into the build. Thanks for the post as we use the updateEntityCustomData mutation as well (although I haven’t experienced any issues).

1 Like

Here’s something I put together for a SQL solution in the meantime. It’s kind of hacky but works:

/* Update Entity Custom Field */

IF OBJECT_ID('dbo.p_EntityCustomFieldUpdate') IS NOT NULL
  DROP PROCEDURE dbo.p_EntityCustomFieldUpdate;
GO

CREATE PROCEDURE dbo.p_EntityCustomFieldUpdate
  @EntityPk NVARCHAR(MAX),
  @CustomFieldName NVARCHAR(MAX),
  @NewFieldValue NVARCHAR(MAX)
AS
  BEGIN
    SET NOCOUNT ON;

    DECLARE @EntityId INT;
    DECLARE @CustomData NVARCHAR(MAX);
    DECLARE @NewCustomData NVARCHAR(MAX);
    DECLARE @FieldData NVARCHAR(MAX);

    DECLARE @CustomFieldsTable TABLE
    (
      Data NVARCHAR(MAX) NOT NULL
    );

    SELECT @EntityId   = Id,
           @CustomData = CustomData
        FROM dbo.Entities
        WHERE Name = @EntityPk;

    DECLARE cur_entity_fields CURSOR LOCAL FAST_FORWARD FOR
    SELECT Value
        FROM OPENJSON(@CustomData);

    OPEN cur_entity_fields;

    FETCH NEXT FROM cur_entity_fields
    INTO @FieldData;

    WHILE @@FETCH_STATUS = 0
      BEGIN

        DECLARE @FieldName NVARCHAR(MAX);

        SELECT @FieldName = FieldName
            FROM
          OPENJSON(@FieldData)
          WITH (FieldName NVARCHAR(MAX) '$.Name');

        IF @FieldName = @CustomFieldName
          BEGIN
            DECLARE @NewFieldData NVARCHAR(MAX);
            SELECT @NewFieldData = JSON_MODIFY(@FieldData, '$.Value', @NewFieldValue);

            INSERT INTO @CustomFieldsTable
            (Data)
            VALUES
            (@NewFieldData);
          END;
        ELSE
          BEGIN
            INSERT INTO @CustomFieldsTable
            (Data)
            VALUES
            (@FieldData);
          END;

        FETCH NEXT FROM cur_entity_fields
        INTO @FieldData;
      END;
    CLOSE cur_entity_fields;
    DEALLOCATE cur_entity_fields;

    SELECT @NewCustomData = N'[' + STRING_AGG(Data, ',') + N']'
        FROM @CustomFieldsTable;

    UPDATE dbo.Entities
        SET CustomData = @NewCustomData
        WHERE Id = @EntityId;

  END;
GO

usage:

dbo.p_EntityCustomFieldUpdate @EntityPk = N'7777777777',
                              @CustomFieldName = N'Address',
                              @NewFieldValue = N'123 Main St'
1 Like

It is same on 5.3.4.

1 Like