How to update record based on unique name, group, category using transform map

vamshi2
Tera Contributor

Hi Team

 

have requirement to check unique name after that group and after that category then update record otherwise ignore

 

using transform map

 

please advice 

1 ACCEPTED SOLUTION

Hi @vamshi2 ,

 

No, check the logic, if name execute and found record then it wont check other two.

Execute the code and check, it will work.

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

View solution in original post

3 REPLIES 3

Runjay Patel
Giga Sage

Hi @vamshi2 

You can do below.

1. in script tag set ignore true if action is insert.

if (action == 'insert' ){
 ignore = true;
 }

 2. create once filed map to with sys_id and write code to check based on three fields.

code:

answer = (function transformEntry(source) {
    var sys_id = "";
    var gr = new GlideRecord('sys_user');
    gr.addQuery('name', cource.u_name);
    gr.query();
    if (gr.next()) {
        sys_id = gr.sys_id;
    } else {
        gr = new GlideRecord('sys_user');
        gr.addQuery('group', cource.u_group);
        gr.query();
        if (gr.next()) {
            sys_id = gr.sys_id;
        } else {
            gr = new GlideRecord('sys_user');
            gr.addQuery('category', cource.u_category);
            gr.query();
            if (gr.next()) {
                sys_id = gr.sys_id;
            }
        }
    }


    return sys_id; // return the value to be put into the target field

})(source);

 

RunjayPatel_0-1731587483891.png

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

 

Hi @Runjay Patel 

 

Thank you so much for response but here I need to check three fields one after other

 

First need to check name then need to check group and then need to check category then I need to update but here in above code it is any one of the fields 

 

 

Please advise 

Hi @vamshi2 ,

 

No, check the logic, if name execute and found record then it wont check other two.

Execute the code and check, it will work.

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------