Pass script include for UI Action

BanuMahalakshmi
Tera Contributor

Hi,

I am using one script include for UI action and Scheduled job script also. UI action button to check and update single location(passing parameter of current page) but scheduled job will check all locations and update the value.

Please advise the correction in the script, thanks in advance.

 

Script Include:

getlocationcontactissue: function()
{
    var locationname = this.getParameter('sysparm_value');
var locationGR = new GlideRecord('cmn_location');
locationGR.addQuery('u_active', true);
locationGR.addQuery('name', locationname);
locationGR.query();
while (locationGR.next()) {
    var errorMessage = '';
    var locationId = locationGR.sys_id.toString();
    errorMessage += checkContactCounts(locationId);
    errorMessage += checkifnotuserContTypes(locationId);
   locationGR.setValue('u_location_issues', errorMessage.trim());
    locationGR.update();
    return errorMessage.trim();
}

function checkContactCounts(locationId) {
    var message = '';
    var primaryContactCount = getContactCount(locationId, 'Primary Site Contact');
    if (primaryContactCount == 0) {
        message += 'Primary Site Contact is missing.' + '\n';
    } else if (primaryContactCount > 1) {
        message += 'Can have only one Primary Site Contact.' + '\n';
    }
}
};
UI Action Script:
  var location = g_form.getValue('name');
    var ga = new GlideAjax('locationcontactissue');
    ga.addParam('sysparm_name', 'getlocationcontactissue');
    ga.addParam("sysparm_value", location);
    ga.getXML(function (response) {
                var answer = response.responseXML.documentElement.getAttribute('answer');
gs.log(answer); //just validating the value
);
 
Scheduled Job:
function checklocationcontacttypeissue() {
   
   var addquery = "ISNOTEMPTY";
    var ga = new GlideAjax('locationcontactissue');
    ga.addParam('sysparm_name', 'getlocationcontactissue');
    ga.addParam("sysparm_value", addquery);
    ga.getXML();
}
6 REPLIES 6

@BanuMahalakshmi 

I already shared how single function can be invoked from GlideAjax and server side.

Please enhance the code further.

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

@BanuMahalakshmi 

Thank you for marking my response as helpful.

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