Auto Populate Entitlement

Pandu3
Tera Contributor

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.

11 REPLIES 11

Pandu3
Tera Contributor

 I have custom field "Type" on Entitlement form with values like 'Provide Support-Hardware' & 'Provide Support-Software'.

along with above conditions need to check one more condition :

if Category : Hardware on case form then I need to check the Type is 'Provide Support-Hardware'

 

for this I created system property and I need to call the property in script include.

Please help me on this .

 

Note: Instead of OnChange() I'm trying to do OnSubmit() client script because I need to select Asset & Category on case form.

 

 

OnSubmit() should not make any difference to the script here.

What exactly is there in the system property? Is it the choice option or any sys_id?

For the additional condition, you can add one more parameter from client script like this:

 

gaCaseEnt.addParam('sysparm_category', g_form.getValue('category'));

 



and in your script include, you can catch that parameter and use similar if else condition:

 

var EntitlementValidation = Class.create();
EntitlementValidation.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkEntitlement: function() {
var assets = this.getParameter('sysparm_assetName');
var category= this.getParameter('sysparm_category');
var type;
if(category=='Hardware')
type= gs.getProperty('<Name of your property>'); //or you can mention the static value
else if(category=='Software')
type=gs.getProperty('<Name of your property>'); //or you can mention the static value

var serviceEnt = new GlideRecord('service_entitlement');
serviceEnt.addQuery('asset', assets);
serviceEnt.addActiveQuery();
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)
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'
});

 

You can use this as a reference and adjust as per your custom conditions.

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



Pandu3
Tera Contributor

What exactly is there in the system property? Is it the choice option or any sys_id?

  • Choice options 

for reference attached screen shots.

 

Ok, these are choice options. Then in your script include, you can simply use the choice values in the category if else part.

Let me know if that works.

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

Pandu3
Tera Contributor

 

Hi Mdash,

Small changes in the requirement .

On case form When Agent selects Asset then recent updated Entitlement has to auto populate as default based on below condition

* Entitlement start date <= current date and End date >= current date

If the condition fails need to display error message " No Active Entitlement".

on the same form if the agent selects category after selecting Asset then based on category, Entitlement has to change. Now Entitlements has to check based on Type field on entitlement form and recent updated Entitlement has to auto populate as default.

Here "Type" is a custom field on Entitlement form with values like 'Provide Support-Hardware' & 'Provide Support-Software'.

Example:

if Category : Hardware on case form ,then I need to check the Type is 'Provide Support-Hardware'

for this I created system property.

Please, Can you help me on this.