Autopopulate reference field from catalog client script calling script include
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2025 12:05 AM
This is catalog client script
function onLoad() {
console.log("✅ onLoad function executed.");
var ga = new GlideAjax("AccountReferenceFilterTwo");
ga.addParam("sysparm_name", "getFilteredAccountsRP");
ga.addParam("sysparm_scope", "global"); // Explicitly set scope // because scriptinclude belong to global scope but client script customer service scope
ga.getXMLAnswer(function(response) {
console.log("📨 Response received:", response);
if (!response) {
console.warn("🚨 No response from Script Include.");
return;
}
try {
var result = JSON.parse(response);
console.log("📊 Parsed JSON:", result);
if (result.filteredAccount) {
console.log("✅ Setting 'account' field:", result.filteredAccount);
g_form.setValue("account", result.filteredAccount);
} else {
console.warn("⚠️ filteredAccount is empty.");
}
} catch (error) {
console.error("❌ Error parsing JSON:", error);
}
});
}
Script INLCLUDE- working good but
Script INLCLUDE- working good but
var AccountReferenceFilterTwo = Class.create();
AccountReferenceFilterTwo.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getFilteredAccountsRP: function() {
var result = {};
var user = gs.getUser();
var userSysId = user.getID();
var grUser = new GlideRecord('sys_user');
if (grUser.get(userSysId)) {
var userClass = grUser.getValue('sys_class_name');
var userActive = grUser.getValue('active');
var userCompany = grUser.getValue('company');
if (userActive == '1' && userClass == 'sys_user') {
result.filteredAccount = 'sys_id'; // sys_id of "Xperi Field Trials"
} else if (userActive == '1' && userClass == 'customer_contact' && userCompany) {
result.filteredAccount = userCompany;
} else {
result.filteredAccount = '';
}
}
return JSON.stringify(result);
},
type: 'AccountReferenceFilterTwo'
});
Account is reference field referencing customer_account table. what we want is a functionality which is autopopulate on page opening, but we need to click on account first. I called this script include from reference qual there it return single value company dropdown but thats not autopopulating that i need to click on single dropdown to choose
Account is reference field referencing customer_account table. what we want is a functionality which is autopopulate on page opening, but we need to click on account first. I called this script include from reference qual there it return single value company dropdown but thats not autopopulating that i need to click on single dropdown to choose
0 REPLIES 0