Auto Populate Entitlement
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2022 10:37 PM - edited 11-21-2022 10:44 PM
Hello,
Based on "Asset" selection on case from need to auto populate the recently updated Entitlement in "Entitlement" field on Case form.
Conditions:
- Selected Asset Entitlements only to show
- Recently updated Entitlement need to populate
- Start Date should not be a future date
- End Date -Future Date
Please, Can anyone help me on this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2022 12:46 AM
Hi There,
Just a few questions.
If there are more than one entitlements associated with an asset, only the latest one will populate?
Start and End dates are fields on the entitlement and contract table. If you already have the entitlement with all details, why do we need to enforce past and future?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2022 08:57 PM
Hello,
- If there are more than one entitlements associated with an asset, only the latest one will populate?
---Yes ,the latest updated entitlement need to populate if more than one entitlements available .
- Start and End dates are fields on the entitlement and contract table. If you already have the entitlement with all details, why do we need to enforce past and future?
here we are checking the entitlement start date <=current date and end date >=current date
Hope I answered your questions. Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2022 09:29 PM
Script include :
var EntitlementValidation = Class.create();
EntitlementValidation.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkEntitlement: function() {
var assets = this.getParameter('sysparm_assetName');
var serviceEnt = new GlideRecord('service_entitlement');
serviceEnt.addQuery('asset', assets);
serviceEnt.addQuery('active', true);
serviceEnt.query();
if (!serviceEnt.next()) {
return 400;
}
},
type: 'EntitlementValidation'
});
Client Script :
var gaCaseEnt = new GlideAjax('global.EntitlementValidation');
gaCaseEnt.addParam('sysparm_name', 'checkEntitlement');
gaCaseEnt.addParam('sysparm_assetName', g_form.getValue('asset'));
gaCaseEnt.getXML(mycallback);
function mycallback(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer == 400) {
getMessage("No active contract entitlement is associated with the asset", function(msg) {
alert(msg);
});
}
}
Through above script I'm checking the Selected Asset has "Active" entitlement or not . If there is no active entitlement available then displaying error message. If active entitlement available then need to auto populate the entitlement with above mentioned validations.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2022 10:26 PM
Thanks for sharing the script.
You can tweak the script include to return valid entitlement.
var EntitlementValidation = Class.create();
EntitlementValidation.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkEntitlement: function() {
var assets = this.getParameter('sysparm_assetName');
var serviceEnt = new GlideRecord('service_entitlement');
serviceEnt.addQuery('asset', assets);
serviceEnt.addActiveQuery();
serviceEnt.orderByDesc('sys_updated_on'); //to get the latest updated record
serviceEnt.setLimit(1);
serviceEnt.query();
if (!serviceEnt.next()) {
return 400;
}
else{
var start= serviceEnt.start_date;
var end= serviceEnt.end_date;
var now= new GlideDate();
if (start>now)
return "Start date should not be in future"; //or some other error code
else if (end<now)
return "End date should not be in the past";//or some other error code
else
return serviceEnt.getUniqueValue();
}
},
type: 'EntitlementValidation'
});
And in your client script, you can add two more conditions
var gaCaseEnt = new GlideAjax('global.EntitlementValidation');
gaCaseEnt.addParam('sysparm_name', 'checkEntitlement');
gaCaseEnt.addParam('sysparm_assetName', g_form.getValue('asset'));
gaCaseEnt.getXML(mycallback);
function mycallback(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer == 400) {
getMessage("No active contract entitlement is associated with the asset", function(msg) {
alert(msg);
});
}else if(answer=="Start date should not be in future"){
getMessage("YOUR CUSTOM MESSAGE", function(msg) {
alert(msg);
});
}
else if(answer=="End date should not be in the past"){
getMessage("YOUR CUSTOM MESSAGE", function(msg) {
alert(msg);
});}
else{
g_form.setValue('asset',answer);
}
}
Notes:
- Please change your alert statements/error codes as required and test it.
- There is an OOTB Reference Qualifier on Entitlement field on Case form. You may need to disable that.
You can mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!
Best Regards