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-25-2022 09:10 PM
So here we are looking at 2 onChange client scripts.
1. When Asset changes
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);
}
}
2. When Category changes
var gaCaseEnt = new GlideAjax('global.EntitlementValidation');
gaCaseEnt.addParam('sysparm_name', 'checkEntitlement');
gaCaseEnt.addParam('sysparm_assetName', g_form.getValue('asset'));
gaCaseEnt.addParam('sysparm_assetCategory',g_form.getValue('category'));
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);
}
}
The script include can be adjusted slightly.
var EntitlementValidation = Class.create();
EntitlementValidation.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkEntitlement: function() {
var assets = this.getParameter('sysparm_assetName');
if(this.getParameter('sysparm_assetCategory'))
var category= this.getParameter('sysparm_assetCategory');
var type;
if(category=='Hardware')
type= gs.getProperty('<Name of your property>'); //or you can mention the static choice value
else if(category=='Software')
type=gs.getProperty('<Name of your property>'); //or you can mention the static choice value
var serviceEnt = new GlideRecord('service_entitlement');
serviceEnt.addQuery('asset', assets);
serviceEnt.addActiveQuery();
if(type)
serviceEnt.addQuery('u_type', type);//query for the exact type
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) || (end<=now))
return "No Active Entitlements."
else
return serviceEnt.getUniqueValue();
}
},
type: 'EntitlementValidation'
});
Then it should work. You can test and further adjust based on requirement.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2022 03:48 AM - edited 12-05-2022 01:47 AM
Hi mdash,
Thank you