Create change request declarative action not setting parent as incident

Debasis Pati
Tera Guru

In serice operation workspace for incident there is a declarative action called 

"Create change request" when clicked on it it opens the change rfc page to select which type of change request i want to create either normal or emergency once i select anything and create a change request its parent should get filled as the incident number but it is not doing that ideally this should do right as we are creating the change from the incident.

Declarative action link
https://yourinstance.service-now.com/sys_declarative_action_assignment.do?sys_id=20aec8ab23323010148...

https://yourinstance.service-now.com/sys_ux_form_action.do?sys_id=64639c7a233230101488dc1756bf65f0&s...

@Ankur Bawiskar can you let me know what can be done to fix this issue?




1 ACCEPTED SOLUTION

@Debasis Pati 

that's OOTB behavior

g_form object only works if the field is present in that view

You can do this

-> let it be on form view i.e. workspace

-> populate it and then hide it

💡 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

10 REPLIES 10

@Debasis Pati 

when I was checking, I found this is the URL

So you can do string manipulation

-> check if the source record is /now/sow/record means it's starting point, then check if URL contains chg_model

-> then do string manipulation and grab the incident sysId which is 32 character

-> also remember the parent field should be on workspace form view so that your client script sets it

AnkurBawiskar_0-1768209161692.png

 

💡 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

Hello @Ankur Bawiskar ,

I have written the below script and it worked.

function onLoad() {
    try {
        var url = String(top.location && top.location.href || window.location.href || '');
        if (url.indexOf('/now/sow/') === -1) {
            return; // Not in SOW / configurable workspace
        }
 
        // Decode URL to handle encoded characters
        var decoded = decodeURIComponent(url);
 
        // Find the sys_id after 'record/incident/'
        var marker = '/record/incident/';
        var idx = decoded.indexOf(marker);
        if (idx === -1) return;
 
        var start = idx + marker.length;
        var tail = decoded.substring(start);
        var endSlash = tail.indexOf('/');
        var candidate = (endSlash === -1) ? tail : tail.substring(0, endSlash);
 
        // Validate 32-character sys_id
        if (candidate && candidate.length === 32) {
          // g_form.setValue('parent',candidate);
          // g_form.setValue('short_description',candidate);
           g_form.setValue('parent',candidate);
        }
    } catch (e) {
        // Fail silently
    }
}
Let me know if you think this is correct or not.

Regards,
Debasis

@Debasis Pati 

Glad to know that my approach worked for you.

Looks fine to me, good to go.

💡 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

Hello @Ankur Bawiskar ,
i have observed one thing.
if the parent field is not added to the form then its setting it as blank.
if the parent field i am adding to the form its working fine.
So i wonder if we do not add the field on the form. How we can achieve this then?

@Debasis Pati 

that's OOTB behavior

g_form object only works if the field is present in that view

You can do this

-> let it be on form view i.e. workspace

-> populate it and then hide it

💡 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