Fetching values from URL - Agent Workspace

ramwons
Kilo Expert

I have to fetch values from the URL (sc_req_item & sysID next to it) and set it in Table field "source_table" & Document ID field "source_record"  on the form respectively.

Sample URL as follows: 

https://xyzdev.service-now.com/now/workspace/agent/record/sc_req_item/7f93e37b1ba33f0020c8fddacd4bcb...

I'm tried following method  but not sure how to use it exactly.. I used the same method for UI16 and it worked as expected

var gURL = new GlideURL();
gURL.setFromCurrent();

 

6 REPLIES 6

Hi Ram,

I doubt this can be achieved

Regards
Ankur

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

Hi @Ankur Bawiskar ,

I changed the script like below. I'm getting values in the variable but the values are not getting set to the form.

Now, I checked the Client script written for UI16 which is also stopped working.. V strange behavior as it worked yesterday and not now. 

 var url = top.location.href;
    alert(url);

    var ritmTab = "sc_req_item";
    if (url.includes(RITMstring)) {
        alert("sc_req_item is in URL");

        var indexOfRITM = url.indexOf(ritmTab);
        var indexOfSysIDstart = indexOfRITM + ritmTab.length + 1; // index of sc_req_item substring start + lenght of sc_req_item substring + 1 (lenght of "/") that means this is index of first char after "...sc_req_item/"  
        var sysIDlenght = 32; // sysID is always 32 chars long
        var ritmID = url.substring(indexOfSysIDstart, indexOfSysIDstart + sysIDlenght);
        g_form.setValue("source_record", ritmID);
        g_form.setValue("source_table", ritmTab);
        g_form.setValue("u_escalation_type", "4");
        alert(ritmID);
    } else {
        alert("sc_req_item is NOT in URL");
    }

Best Regards,

Ram