Unable to insert record in group member table through flow designer

Toshu
Tera Contributor

I have a flow designer developed for AD integration with Servicenow through AD spoke

While trying to add user to group in Servicenow instance after adding the users to the AD group I am getting an error that says "Error occurred while inserting record : null"

I have referred to the KB article available but they do not provide a clear fix as expected

I have already referred to these KBs: https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0827213

And related KBs to this error but unable to find a fix

 Below is the flow with error execution:

 

find_real_file.png

Actual flow logic:

find_real_file.png

Please let me know if you could find the issue?

 

21 REPLIES 21

A_maity002
Tera Contributor

Hello @Radek ,

 

It will be helpful for me, could you please send me the details ?

 

Kind Regards,

Atanu Maity

 

Here is a step by step guide to avoid this type of error for adding user in HR. You need HR admin but system doesn't have this role in OOB:

 

Mark this as helpful so others can see this!

 

1. Create Scheduled Script Execution, according your needs where Run as account will have the right to perform the action - see picture 

a.png

 

2. Create custom Flow Designer Action to trigger this Scheduled Script Execution - see picture 

c.png

 

Script for Flow Desiner Action: Execute script (Add user to group): 

(function execute(inputs, outputs) {
 
var sysid = inputs.sysid;
var user = inputs.usr;
var group = inputs.grp;
 
try {
    //replace sysids in existing record
var gr = new GlideRecord("sysauto_script");
    if (gr.get(sysid)) {
        var text = gr.script;
        // break the textblock into an array of lines
        var lines = text.split('\n');
        // remove 2 lines, starting at the first position
        lines.splice(0,2);
        // join the array back into a single string
        var newtext = lines.join('\n');
        var newScript = "var NEWuser = '" + user + "';";
        newScript += "\n" + "var HRgroup = '" + group + "';";
        newScript += "\n" + newtext;
        gr.script = newScript;
        gr.update();
    }
     
    //execute the updated script
    var schedGr = new GlideRecord("sysauto_script");
    if (schedGr.get(sysid)) {
        gs.executeNow(schedGr);
    }
 
}
catch (ex) {
      //throw new Error('Unable to find sysauto_script with sys_id  passed from event '+ex.message);
}
 
})(inputs, outputs);

 

3. In your Flow or Sub-Flow - make sure you run this script under certain condition - example - if HR group - use this script solution - see picture 

 

b.png

 

Please note this is kinda dirty workaround and it can be adjusted - for example you can create copy of the scheduled script execute and delete it after, so you always use unique sys_id every time the script runs. With my solution if there are 2 actions running at the same time one of them will fail most likely.

It's crazy that this post is from '22 and it's still an issue. I'm running into the same error. Will try what you've recommended.

One additional advice based on my experience, create the scheduled script as template. When you need to execute the script - create copy of this record - update values in the script - execute and delete it after.

This way you can run multiple sessions at the same time.

Radek
Tera Expert

Same issue here, I'll try what Olan suggested