Some PDIs are currently unavailable, and PDI actions are paused. View the latest updates here. Read More

Record is not being created in Decision table with concatenated query

santoshsuta
Tera Contributor

I am creating a record in Decision Table using catalog item.  
I cannot use Record producer on this sys_decision_question table due to the security constrains. So, I am using catalog item and creating a record using the flow script.
Somehow the script is working with the hardcoded values (Please refer below script action)

 

-------------------Script Starts from here----------------------------

(function execute(inputs, outputs) {

    try {

        gs.info("Santosh inside");

 

        var state = inputs.state;

        gs.info("Santosh state: " + state);

        var board = inputs.board;

        gs.info("Santosh Board: " + board);

        var decisionTable = inputs.decisionTable;

        gs.info("Santosh decisionTable: " + decisionTable);

        var taskType = (inputs.taskType || "").trim().toLowerCase();

        gs.info("Santosh taskType: " + taskType);

        var lane = inputs.lane;

        gs.info("Santosh lane: " + lane);

 

        var finalTasktype = "";

        var finalCondition = "";

 

       

        if (taskType === "private task") {

            finalTasktype = "vtb_task";

            finalCondition = 'u_rm_story_state=3^u_vtb_kanban_board=02b2d2e6db6fd01041899b3c8a96194e^EQ';

        }

        else if (taskType === "incident") {

            gs.info("Santosh taskType matched 'incident'");

            finalTasktype = "incident";

            finalCondition = 'u_incident_state=' + state + '^u_vtb_kanban_board=02b2d2e6db6fd01041899b3c8a96194e^EQ';

        }

        else {

            gs.warn("Santosh Warning: taskType '" + taskType + "' does not match any condition.");

        }

 

        if (!finalCondition) {

            gs.warn("Santosh Warning: finalCondition is empty for taskType '" + taskType + "'");

        }

 

        if (!decisionTable) {

            gs.error("Santosh Error: decisionTable sys_id is empty or null!");

            return;

        }

 

        gs.info("Santosh finalCondition: " + finalCondition);

 

        var questions = [

            {

                condition: "u_incident_state=6^u_vtb_kanban_board=02b2d2e6db6fd01041899b3c8a96194e^EQ"

                answer: [

                    { value: lane }

                ],

                active: true,

                defaultAnswer: false,

            }

        ];

 

        gs.info("Santosh DEBUG: Questions array prepared - " + JSON.stringify(questions));

 

        var dt = new sn_dt.DecisionTableAPI();

        var response = dt.createQuestions(decisionTable, questions);

 

        gs.info("Santosh DEBUG: DecisionTableAPI Response - " + JSON.stringify(response));

 

        if (response && response.results && response.results.length > 0 && response.results[0].record) {

            gs.info('Santosh Status: ' + response.status);

            gs.info('Santosh First decision sys_id: ' + response.results[0].record.getValue('sys_id'));

        } else {

            gs.warn('Santosh No valid results found in the API response.');

        }

 

    } catch (error) {

        gs.error("Santosh Exception occurred: " + error);

    }

})(inputs, outputs);

-----------------------The script ends here-------------------------------------

The record is being created with the correct Filter conditions and correct Answer value.

BUT 
When I replace the condition hardcoded value with the below mentioned concatenated query. It doesn't works
for example:
finalCondition = 'u_incident_state=' + state + '^u_vtb_kanban_board=02b2d2e6db6fd01041899b3c8a96194e^EQ';

var questions = [

            {

                condition: finalCondition

                answer: [

                    { value: lane }

                ],

                active: true,

                defaultAnswer: false,

            }

        ];


I am getting correct logs mentioned below.

Santosh finalCondition: u_incident_state=6^u_vtb_kanban_board=02b2d2e6db6fd01041899b3c8a96194e^EQ

 

Santosh DEBUG: Questions array prepared -  [{"condition":"u_incident_state=6^u_vtb_kanban_board=02b2d2e6db6fd01041899b3c8a96194e^EQ","answer":[{"value":"43a6ae521b0c661092b275de034bcb32"}],"active":true,"defaultAnswer":false}]

This is an additional log says that it's failed to created a record in decision table.
Santosh DEBUG: DecisionTableAPI Response - {"results":[{"errors":[{"message":"Type mismatch occurred in the field condition when expecting value of type String","type":"INVALID_REQUEST"}],"status":"Failure"}],"errors":[{"message":"1 requests failed","type":"INVALID_REQUEST"}],"status":"Failure"}

Please let me know if anyone have any idea on this.

3 REPLIES 3

Thank you so much Raj, That worked. 🙂

RajC59005800307
Tera Guru

@santoshsuta If my response helped you in any way consider making it as helpful 
thank you !

Kindly mark it correct and helpful if it is applicable.

Thanks,

Raj

Already accepted a solution and marked as accepted.