Script inlcude
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2024 11:13 PM
Hidden from the Client side/user.
Dependency on a change to be done from platform system.
Services identify field value is present "Account "table.
Field Name : Account , backend value = account_name , reference to ACCOUNTS[u_accounts]
u_identify_reference = identify_database_ref
u_account_definition = 00100095
u_bisource_name = AD
u_status active/inactive.
Above condition to build the script include and client side.
Any idea how to build above example task help me with code .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2024 11:47 PM
Hi @Ram012
Here is sample code which you can utilize:
script include
var AccountUtils = Class.create();
AccountUtils.prototype = {
initialize: function() {},
getAccountDetails: function(accountName) {
var accountGR = new GlideRecord('u_accounts'); // Adjust this if necessary
accountGR.addQuery('account_name', accountName);
accountGR.addQuery('u_status', 'active'); // Only get active accounts
accountGR.query();
if (accountGR.next()) {
return {
u_identify_reference: accountGR.u_identify_reference,
u_account_definition: accountGR.u_account_definition,
u_bisource_name: accountGR.u_bisource_name
};
}
return null; // Return null if no active account found
},
type: 'AccountUtils'
};
Then client script on 'Your target table' (e.g., Incident, change, request, etc)
onLoad / onChange - decide as per your requirement:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
// Call the Script Include
var ga = new GlideAjax('AccountUtils');
ga.addParam('sysparm_name', 'getAccountDetails');
ga.addParam('sysparm_account_name', newValue); // Pass the account name
ga.getXMLAnswer(function(response) {
var accountDetails = JSON.parse(response);
if (accountDetails) {
// Populate fields with the returned values
g_form.setValue('u_identify_reference', accountDetails.u_identify_reference);
g_form.setValue('u_account_definition', accountDetails.u_account_definition);
g_form.setValue('u_bisource_name', accountDetails.u_bisource_name);
} else {
// Handle case where account is not found or inactive
g_form.setValue('u_identify_reference', '');
g_form.setValue('u_account_definition', '');
g_form.setValue('u_bisource_name', '');
// Optionally show a message to the user
g_form.addErrorMessage('Account not found or inactive.');
}
});
}
Ensure the fields u_identify_reference, u_account_definition and u_bisource_name exist on the form and are set to read-only or hidden as per your requirement.
i hope my answer helps you to resolve your issue, if yes please mark my answer helpful and correct.
thank you
rajesh