Getting "offending token" when invoking a Create Record resource

thomaskennedy
Tera Guru

When I invoke my Create Record resource I get the following response:

	{
    "dataElemId": "create_service_request",
    "operation": "EXECUTE",
    "errors": [
        {
            "message": "Invalid Syntax : offending token ')' at line 3 column 31",
            "errorType": "InvalidSyntax",
            "locations": [
                {
                    "line": 3,
                    "column": 31
                }
            ]
        }
    ],
    "__uxfCompositionElId": "7dc52bc487105910d420f29acebb355b"
}

I have no idea what it can be referring to. My request is simple:

function handler({api, event, helpers, imports}) {

    const device = api.context.props.deviceSysid || "";
    const problem = api.state.problem || "";
    const comment = api.state.comment || "";
    const status = "to_service";
    
    var query = `u_device=${device}`;
    query += `^u_problem=${problem}`;
    query += `^u_comments=${comment}`;
    query += `^u_status=${status}`;  

    var payload = {
            "table": "<scope>.<table>",
            "templateFields": query,
            "useSetDisplayValue": false
        };
    api.data.create_service_request.execute(query);
}

So the payload will be, for example:

u_device=cdf59c6087ffcd90d420f29acebb3582^u_problem=no_flash^u_comments=some text^u_status=to_service

No record is created.

1 ACCEPTED SOLUTION

thomaskennedy
Tera Guru

Had to fix two things.

 Fix #1, pass the whole payload, not just the query.

api.data.create_service_request.execute(payload);

Fix #2, remove the scope from the table propety. If that is included you will get "provideField called for a non-valid GraphqlDynamicObjectType".

var payload = {
            "table": "<table>",
            "templateFields": query,
            "useSetDisplayValue": false
        };

So the fixed version is:

    var query = `u_device=${device}`;
    query += `^u_problem=${problem}`;
    query += `^u_comments=${comment}`;
    query += `^u_status=${status}`;

    var payload = {
            "table": "<table>",
            "templateFields": query,
            "useSetDisplayValue": false
        };
    api.data.create_service_request.execute(payload);

View solution in original post

1 REPLY 1

thomaskennedy
Tera Guru

Had to fix two things.

 Fix #1, pass the whole payload, not just the query.

api.data.create_service_request.execute(payload);

Fix #2, remove the scope from the table propety. If that is included you will get "provideField called for a non-valid GraphqlDynamicObjectType".

var payload = {
            "table": "<table>",
            "templateFields": query,
            "useSetDisplayValue": false
        };

So the fixed version is:

    var query = `u_device=${device}`;
    query += `^u_problem=${problem}`;
    query += `^u_comments=${comment}`;
    query += `^u_status=${status}`;

    var payload = {
            "table": "<table>",
            "templateFields": query,
            "useSetDisplayValue": false
        };
    api.data.create_service_request.execute(payload);