How to carry over category and subcategory from incident to change in related list

ernestogome
Tera Contributor

Hi, I just wanna say that I am very new to Snow and I'm just getting to know the platform.

I got assigned the following task:

I would like the category and subcategory of incident to carry over to change records when a change is created from an incident record.

In the incident form, I have the change request related list in which I can submit a new change by clicking the New button. This button redirects me to sn_chg_model_ui_landing.do, not to the change_request.do page. How do I manage to carry over the cat and subcat from my incident? I know I can do it via params in the URL:

sysparm_query=^category=categorytest

But it doesn't work when I select the model from the sn_chg_model_ui_landing.do. Any help?




2 ACCEPTED SOLUTIONS

Bhavya11
Kilo Patron

Hi @ernestogome 

 

you can try with before Business rule to map the category and subcategory from incident to change but make sure the value of the category and subcategory of incident and also change is same.

 

if yes then try this way

 

Table: Change Request (change_request)

When: before

Insert: Checked

Condition: parent is not empty.

Bhavya11_0-1766984786767.png

 

Script:

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

var parentRec = current.parent.getRefRecord(); 
    
    if (parentRec.isValidRecord() && parentRec.getTableName() == 'incident') {
        // Copy the values
        current.category = parentRec.category;
        current.subcategory = parentRec.subcategory;
    }
})(current, previous);

 

If this information proves useful, kindly mark it as helpful or accepted solution.

 

Thanks,

BK

If this information proves useful, kindly mark it as helpful or accepted solution.

Thanks,
BK

View solution in original post

Ankur Bawiskar
Tera Patron

@ernestogome 

see when you click New button in related and when new CHG form is opened if INC sysId is there in URL

if yes then extract that and then query it in display business rule on change_request and use that to get category subcategory and set it on CHG

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

View solution in original post

6 REPLIES 6

Bhavya11
Kilo Patron

Hi @ernestogome 

 

you can try with before Business rule to map the category and subcategory from incident to change but make sure the value of the category and subcategory of incident and also change is same.

 

if yes then try this way

 

Table: Change Request (change_request)

When: before

Insert: Checked

Condition: parent is not empty.

Bhavya11_0-1766984786767.png

 

Script:

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

var parentRec = current.parent.getRefRecord(); 
    
    if (parentRec.isValidRecord() && parentRec.getTableName() == 'incident') {
        // Copy the values
        current.category = parentRec.category;
        current.subcategory = parentRec.subcategory;
    }
})(current, previous);

 

If this information proves useful, kindly mark it as helpful or accepted solution.

 

Thanks,

BK

If this information proves useful, kindly mark it as helpful or accepted solution.

Thanks,
BK

Ankur Bawiskar
Tera Patron

@ernestogome 

see when you click New button in related and when new CHG form is opened if INC sysId is there in URL

if yes then extract that and then query it in display business rule on change_request and use that to get category subcategory and set it on CHG

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

Najmuddin Mohd
Mega Sage

Hello @ernestogome ,

When you are creating a Change from the related list, and the Change is not yet saved, you can see the incident SysID in the URL at the end, which will become the parent of this Change.

You can write a Client script and extract Incident SysID using URL Parameters, and populate the Category and Subcategory.

You can check the below link to extract URL Parameters.
https://www.servicenow.com/community/service-management-articles/extracting-url-parameters-in-servic...


If the above information helps you, Kindly mark it as Helpful and Accept the solution.
Regards,
Najmuddin

Hi! How would I be able to extract the category from an client script? I understand how to retrieve the sysId from the URL, but how do i get the category? As far as I know, it's not posible to use GlideRecord on client scripts.