Pls advise how to get current record sys_id into scriptinclude

BanuMahalakshmi
Tera Contributor

Hi,

Please advise to get sysid of current location value into script include.

I am fetching location name from current record (UI action) and passing to script include. 

UI Action:

 var location = g_form.getvalue('name');
    var ga = new GlideAjax('ContactLocation');
    ga.addParam('sysparm_name', 'getlocation');
    ga.addParam("sysparm_value", location);
    ga.getXML(function(response) {
        var answer = response.responseXML.documentElement.getAttribute('answer');
        g_form.setValue('fieldname', answer);
        g_form.save();
    });

 

Script Include:

 
Query by sys_id of current location instead of name
    getlocation: function() {
        var locationsysid = this.getParameter('sysparm_value');
       // var locationsysid = locationname.sys_id;
            
        var locationGR = new GlideRecord('cmn_location');
        locationGR.addQuery('u_active', true);
        if (locationsysid != '') {

            locationGR.addQuery('sys_id', '=',locationsysid);
        }
 
Thanks.

 

 

 

 

 

 

 

 

8 REPLIES 8

sunil maddheshi
Tera Guru

@BanuMahalakshmi 


I think your Script Include needs to query using name, not sys_id:
getlocation: function() {
var locationName = this.getParameter('sysparm_value');

var locationGR = new GlideRecord('cmn_location');
locationGR.addQuery('u_active', true);
locationGR.addQuery('name', locationName);
locationGR.query();

if (locationGR.next()) {
return locationGR.getUniqueValue(); // returns sys_id
}
return '';
}

 

Please mark correct/helpful if this helps you

Ankur Bawiskar
Tera Patron
Tera Patron

@BanuMahalakshmi 

is name field on form a string?

if yes then you need to query location table with that name and then get sysId

please share some screenshots and what's your requirement

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

i need to fetch current location record sysid then i pass it to Script include

@BanuMahalakshmi 

sorry but you didn't these 2 questions which I posted in my earlier response

-> is name field on form a string?

-> please share some screenshots and what's your requirement

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