The CreatorCon Call for Content is officially open! Get started here.

Create new variables on existing RITM's

Tzach Benbenist
Tera Guru

Hello,

 

I have a requirment to add 2 new reference variables instead of 2 old string fields.

I want to create data fix to the existing records and switch between the fields on the variable editor view.

The problem is that the existing record created without these new ref fields.

There is a way to create those new variables to the existing records?

 

Thank you 🙂

1 ACCEPTED SOLUTION

I found solution 🙂

This is the script:

 

var ReqLog = new GlideRecord("staging table");

ReqLog.addEncodedQuery("u_requestISNOTEMPTY");

ReqLog.addQuery("sys_id", "4203efe6938935104bb035aa6aba1062"); //Test value

ReqLog.query();

if (ReqLog.next()) {

    var ritm = new GlideRecord("sc_req_item");

    ritm.addQuery("request", ReqLog.u_request.sys_id);

    ritm.query();

    if (ritm.next()) {

        var option1 = createOption("93d8c711933eb15046fbff8a6aba10ec", getRefMan(ReqLog.u_yyhr_manager), 28); //question,value,order

        var option2 = createOption("88498b11933eb15046fbff8a6aba1069", getRefMan(ReqLog.u_yyhr_new_manager), 29); //question,value,order

        createOptionM2M(ritm.sys_id, option1); //ritm_id, dependant_item

        createOptionM2M(ritm.sys_id, option2);

        ritm.update();

    }

}

 

function createOption(question, value, order) {

    var gr = new GlideRecord("sc_item_option");

    gr.initialize();

    gr.item_option_new = question;

    gr.value = value;

    gr.order = order;

    return gr.insert();

}

 

function createOptionM2M(ritm_id, dependant_item) {

    var gr = new GlideRecord("sc_item_option_mtom");

    gr.initialize();

    gr.request_item = ritm_id;

    gr.sc_item_option = dependant_item;

    return gr.insert();

}

 

function getRefMan(emp_id) {

    var int_id = Number(emp_id.toString());

    var id = int_id.toString();

    var gr = new GlideRecord("sys_user");

    gr.addQuery("employee_number", id);

    gr.query();

    if (gr.next()) {

        return gr.sys_id;

    }

}

 

View solution in original post

7 REPLIES 7

I found solution 🙂

This is the script:

 

var ReqLog = new GlideRecord("staging table");

ReqLog.addEncodedQuery("u_requestISNOTEMPTY");

ReqLog.addQuery("sys_id", "4203efe6938935104bb035aa6aba1062"); //Test value

ReqLog.query();

if (ReqLog.next()) {

    var ritm = new GlideRecord("sc_req_item");

    ritm.addQuery("request", ReqLog.u_request.sys_id);

    ritm.query();

    if (ritm.next()) {

        var option1 = createOption("93d8c711933eb15046fbff8a6aba10ec", getRefMan(ReqLog.u_yyhr_manager), 28); //question,value,order

        var option2 = createOption("88498b11933eb15046fbff8a6aba1069", getRefMan(ReqLog.u_yyhr_new_manager), 29); //question,value,order

        createOptionM2M(ritm.sys_id, option1); //ritm_id, dependant_item

        createOptionM2M(ritm.sys_id, option2);

        ritm.update();

    }

}

 

function createOption(question, value, order) {

    var gr = new GlideRecord("sc_item_option");

    gr.initialize();

    gr.item_option_new = question;

    gr.value = value;

    gr.order = order;

    return gr.insert();

}

 

function createOptionM2M(ritm_id, dependant_item) {

    var gr = new GlideRecord("sc_item_option_mtom");

    gr.initialize();

    gr.request_item = ritm_id;

    gr.sc_item_option = dependant_item;

    return gr.insert();

}

 

function getRefMan(emp_id) {

    var int_id = Number(emp_id.toString());

    var id = int_id.toString();

    var gr = new GlideRecord("sys_user");

    gr.addQuery("employee_number", id);

    gr.query();

    if (gr.next()) {

        return gr.sys_id;

    }

}

 

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Tzach Benbenist 

 

There is a way to create those new variables to the existing records?

Atul; NO, new variable will be available for new Request only.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

I already found a solution.

There is a way to create those variables via script.

You can find the script above.