Create a change from a Risk

Glenn Vattudal
Tera Expert

Hello.

I am aiming to create a UI action on the risk form (or mitigation task) for creating a change. The normal create change will work just fine (that is the OOTB UI action with 6 lines of code). However I would like to 1. create the change and 2. grab the change_requets record and put it in a reference field (u_change) on the risk form. I am trying the below script but it doesn't work. Can someone guide me:

 

1. This one works:

function openCreateChange() {
    var sys_id = g_form.getUniqueValue();
    var url = '/change_request.do';
    url += '?sys_id=-1&sysparm_query=sn_risk_risk=' + sys_id;
    g_navigation.openPopup(url);
}

This doesn't work:

function createChangeAndLink() {
    var riskRecord = g_form.getUniqueValue();
    var changeRecord = new GlideRecord('change_request');

    changeRecord.setValue('short_description', 'Change for Risk: ' + riskRecord);
    var changeSysId = changeRecord.insert(); 

    if (changeSysId) {
        var riskRecordToUpdate = new GlideRecord('sn_risk_risk');
        if (riskRecordToUpdate.get(riskRecord)) {
            riskRecordToUpdate.setValue('u_change', changeSysId);
            riskRecordToUpdate.update();
        }
    }
    var url = '/change_request.do';
    url += '?sys_id=-1&sysparm_query=sn_risk_risk=' + riskRecord;
    g_navigation.openPopup(url);
}
createChangeAndLink();

 

/Glenn

 

2 REPLIES 2

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Glenn Vattudal 

 

May I know, what is need to duplicate change data on Risk form?

*************************************************************************************************************
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]

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

If you are referring to the reference field it is just for the purpose of looking it up. No other duplication. Rather transfer of information to the change record.

 

/Glenn