Second Approval not required if selected user is same

Ajay Singh2
Tera Contributor

HI All,

 

There is a requirement like in a catalog form there is two field with reference type and one field is Variable filed with name ABC Owner and second field is Variable set Data Owner and both are reference type field with sys_user table and if i select same user in both field than an additional approval is not required only one approval required but if i select both diffrenet user than 2 approvals is required. For example, if Aman is the ABC Owner, provides her approval and then is also one of the Data Owner approvers listed, a 2nd approval is not required to generate for Aman.

How to achieve this in workflow.

 

Thank You!! 

20 REPLIES 20

I used below script after Approval User but its not working.

answer = ifScript();

function ifScript() {
var abcOwner = current.variables.u_frpa_fnrole_owner.sys_id; // Replace 'abc_owner' with your actual variable name
var dataOwner = current.variables.u_data_owner_field.sys_id; // Replace 'data_owner' with your actual variable name

if (abcOwner == dataOwner) {
return 'yes'; // Same user, no additional approval needed
} else {
return 'no'; // Different users, additional approval needed
}
}

@Ajay Singh2 

so you are using workflow and not flow

You are using IF activity in workflow

try this and add logs and see

answer = ifScript();

function ifScript() {
    var abcOwner = current.variables.u_frpa_fnrole_owner.toString(); // Replace 'abc_owner' with your actual variable name
    var dataOwner = current.variables.u_data_owner_field.toString(); // Replace 'data_owner' with your actual variable name

    gs.info('abc owner' + abcOwner);
    gs.info('data owner' + dataOwner);
    if (abcOwner == dataOwner) {
        return 'yes'; // Same user, no additional approval needed
    } else {
        return 'no'; // Different users, additional approval needed
    }
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

In both fields i am getting undefined.
Data Owner sys_id: undefined
ABC Owner sys_id: undefined

@Ajay Singh2 

variable names are correct?

share variable config screenshots.

both variables are of type reference referring to sys_user?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

when i remove .toString() from abc and dataowner than abc sysid get printed but for data owner its undefined i think its variable sets and coming from multirow that why.

answer = ifScript();

function ifScript() {
    var abcOwner = current.variables.u_frpa_fnrole_owner;
    var dataOwner = current.variables.u_data_owner_field;

    gs.info('abc owner:' + abcOwner);
    gs.info('data owner:' + dataOwner);
    if (abcOwner == dataOwner) {
        return 'yes'; // Same user, no additional approval needed
    } else {
        return 'no'; // Different users, additional approval needed
    }
}