Cannot Use XML WAIT in service portal

Sunpreetk
Tera Contributor

This is my code that i used to replace xmlwait because it is giving error in the portal but this code not working.

function onChange() {
var prefix = 'CXP';
var startingIndex = 100001;

// Fire GlideAjax but DO NOT block form submission
setTimeout(function() {
var ga = new GlideAjax('sn_hr_le.contractorOnboardingUtils');
ga.addParam('sysparm_name', 'generateContractorId');
ga.getXMLAnswer(function(latestId) {
var nextNumber;

if (latestId && latestId.length > 3) {
var numericPart = latestId.substring(3);
var numValue = parseInt(numericPart);
nextNumber = isNaN(numValue) ? prefix + startingIndex : prefix + (numValue + 1);
} else {
nextNumber = prefix + startingIndex;
}

g_form.setValue('u_contractor_id', nextNumber);
});
}, 10); // delay the call slightly

return true; // Allow the form to submit immediately
}
script include:
var contractorOnboardingUtils = Class.create();
contractorOnboardingUtils.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

generateContractorId: function() {
var latestId = '';
var userGr = new GlideRecord('sn_hr_core_profile');
userGr.addQuery('u_contractor_id', 'STARTSWITH', 'CXP');
userGr.orderByDesc('u_contractor_id');
userGr.query();
if (userGr.next()) {
latestId = userGr.getValue('u_contractor_id');
}
return latestId;
},

type: 'contractorOnboardingUtils'
});
0 REPLIES 0