Smart Assessment Assessors set in flow

Coyote IV
Tera Guru

Good day.  I am creating a smart assessment using a flow against the pm_program table.  I am having an issue setting "Assessors" via a script.  I would like to combine the program_manager and additional_assignee_list fields as assessors.  Tried various solutions and many fail with some form of isValidRecord error.   Tried a few AI engines - none helped.    Does someone have an example of the "Assessors" field in flow action "Trigger Smart Assessment" being set by a script?  Greatly appreciate any pointers.  Thank you. 

1 ACCEPTED SOLUTION

Again, thank you for your reply.  Based on another article I found simply returning a list will not work - 😞  I found a solution by combining the list of user IDs (ids in your code above) and used action "Look up records" to generate a list and returned that ... 

 

CoyoteIV_0-1791829261627.png

 

View solution in original post

4 REPLIES 4

IbrarA
Kilo Sage

Hi @Coyote IV 

Assessors is a List input, so it needs actual user records, not a comma separated string of sys_ids. That's why you get the isValidRecord error, the action runs that check on every entry.

 

In your flow, add a Script step above the Trigger Smart Assessment action.

 

On that script step, add an input called "current" and drag in your Program record data pill. Then add an output called "assessors" with type List. Paste this into the Script field:

 

(function execute(inputs, outputs) {

    var ids = [];

 

    var pm = inputs.current.program_manager.toString();

    if (pm) ids.push(pm);

 

    var extra = inputs.current.additional_assignee_list.toString();

    if (extra) {

        extra.split(',').forEach(function(id) {

            id = id.trim();

            if (id && ids.indexOf(id) < 0) ids.push(id);

        });

    }

 

    var assessors = [];

    ids.forEach(function(id) {

        var gr = new GlideRecord('sys_user');

        if (gr.get(id) && gr.active) assessors.push(gr);

    });

 

    outputs.assessors = assessors;

})(inputs, outputs);

 

 

Then open the Trigger Smart Assessment action and drag the script step's "assessors" output into the Assessors field.

 

The "gr.get(id)" check keeps bad entries out, since an inactive or deleted user sitting in additional_assignee_list will throw the same error.

 

Docs showing what inputs the action expects: https://www.servicenow.com/docs/bundle/yokohama-governance-risk-compliance/page/product/assessment-e...

 

 

Thanks

ibrar

Thank you for the reply.  I tried a similar approach and found this is not creating an actual list of objects.  The attached image shows the output from an action you described above.  The assassorList is what is returned as a list of assessors where the additional_assgnee_list shows names from the sys_user table.   

 

CoyoteIV_0-1791823420561.png

 

Thanks for posting that output, it tells the story. The script is handing back objects rather than something the Assessors field can take, which is why you're seeing the table name in the list.

Let the platform build the record list instead. Change the script step so it outputs a plain string of sys_ids. Rename the output to assessorIds with type String, and use this:

(function execute(inputs, outputs) {

    var ids = [];

 

    var pm = inputs.current.program_manager.toString();

    if (pm) ids.push(pm);

 

    var extra = inputs.current.additional_assignee_list.toString();

    if (extra) {

        extra.split(',').forEach(function(id) {

            id = id.trim();

            if (id && ids.indexOf(id) < 0) ids.push(id);

        });

    }

 

    outputs.assessorIds = ids.join(',');

})(inputs, outputs);

 

Then add a Look Up Records action after it, Table set to User, condition Sys ID is one of, and drag the assessorIds pill into the value.

Finally drag the Look Up Records action's Records output into Assessors on Trigger Smart Assessment. That output is a proper Records list of sys_ids, which is what the field is after:

https://www.servicenow.com/docs/r/australia/build-workflows/workflow-studio/lookup-records-flow-desi...

If it still errors, could you share a screenshot of the Assessors input definition on the action?

ibrar

Again, thank you for your reply.  Based on another article I found simply returning a list will not work - 😞  I found a solution by combining the list of user IDs (ids in your code above) and used action "Look up records" to generate a list and returned that ... 

 

CoyoteIV_0-1791829261627.png