Create change using the entered values in catalog form/ritm

AKASH BANERJEE
Mega Guru

We have a requirement in which user will enter values in catalog form, then RITM will be created and after that change is created, and when the change is closed, the ritm will be closed automatically. Please let me know how we can implement this requirement in servicenow.

8 REPLIES 8

Hi @Nayan Dhamane ,

 

Thankyou for the solution.

If possible can you please provide me the script.

Hello @AKASH BANERJEE ,

Gunjan has replied to your script you can go by that approach too. If you require a solution by my approach let me know I will develop it and attach the screenshots for you.

BR,
Nayan

If my answer solved your issue, please mark my answer as Correct & Helpful based on the Impact

Best Regards,
Nayan Dhamane
ServiceNow Community Rising Star 2023.

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @AKASH BANERJEE ,

You can create BR on request item table as below

On After Insert

Condition : Item is 'your catalog item name'

GunjanKiratkar_0-1668763287505.png

 

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var gr = new GlideRecord("change_request");
    gr.initialize();
gr. u_requested_item=current.sys_id; //Establish connection between them using this
	gr.short_description=current.variables.variableName;
	gr.cmdb_ci=current.variables.variableName;
	//mapp all your catalog variables like this // Repalce "variableName" with variable backend name
	gr.insert()
})(current, previous);

 

 Create new field as requested item on change form :-

GunjanKiratkar_1-1668763755474.png

 

Write down BR on Change request table :-

GunjanKiratkar_2-1668763946185.png

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var gr = new GlideRecord("sc_req_item");
    gr.addQuery("sys_id", current.u_requested_item);
    gr.query();
    if (gr.next()) {
        gr.state = '3';
        gr.stage = 'complete';
        gr.update();
    }

})(current, previous);

 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

AKASH BANERJEE
Mega Guru

I have figured out the below script in workflow, which is taking values from workflow but the issue is workflow is running fine but it is not creating a normal change. Please let me know what is the issue behind it.

 

var chg = new GlideRecord('change_request');

chg.initialize();

chg.type = 'normal'; //static values
chg.u_change_template = 'example 1'; //static values
chg.assignment_group = 'Group xyz';//static values
chg.requested_by = current.variables.requested_by;
chg.category = current.variables.category;
chg.u_business_application = current.variables.business_application;
chg.cmdb_ci = current.variables.configuration_item;
chg.risk = current.variables.risk;
chg.u_technical_approval_groups = current.variables.change_management_group;
chg.short_description = current.variables.short_description;
chg.description = current.variables.description;
chg.justification = current.variables.justification;
chg.implementation_plan = current.variables.implementation_plan;
chg.risk_impact_analysis = current.variables.risk_and_impact_analysis;
chg.backout_plan = current.variables.backout_plan;
chg.test_plan = current.variables.test_plan;
chg.start_date = current.variables.planned_start_date;
chg.end_date = current.variables.planned_end_date;

chg.insert();