I want to create the automation of user entitlements when users request an application and software request is apploved

sudaporn
Giga Expert

find_real_file.png

I want to create the automation of user entitlements or device entitlements

find_real_file.png

Can i used workflow   scripting   on RITM table.     this my script   but not working   . please recommence me

try {

    var gr = new GlideRecord("alm_entitlement");

    var counter = new GlideRecord("sam_sw_counter");

    counter.addQuery("sys_id", "=", current.variables['model.display_name']);

    gr.query();

    if (counter.next()){

    current.variable.requested_for1=counter.display_name;

  gs.addErrorMessage(gs.getMessage('current.variable.requested_for1'));

    }

  if (gr.next()){

  var gr = new GlideRecord('alm_entitlement');

  //gr.allocated_to = device.sys_id;

  gr.assigned_to = current.variable.requested_for1;

  gr.insert();

}

  } catch(err) {

      gs.log("Error");

  }

1 ACCEPTED SOLUTION

Hi Sudaporn,



I'm guessing you should change the reference of the variable "Sw_asset1" from "Software counter" to "Software Licenses [alm_license]".



I have just tried using the below code in my test-instance, record inserted correctly:



var user_entitlement = new GlideRecord('alm_entitlement_user');


  user_entitlement.initialize();


  user_entitlement.assigned_to = current.variables.Requested_for1;


  user_entitlement.licensed_by = current.variables.Sw_asset1;


  user_entitlement.insert();



Capture.PNG



Please tweak and test as you require.


View solution in original post

12 REPLIES 12

Hi Sudaporn,



I'm guessing you should change the reference of the variable "Sw_asset1" from "Software counter" to "Software Licenses [alm_license]".



I have just tried using the below code in my test-instance, record inserted correctly:



var user_entitlement = new GlideRecord('alm_entitlement_user');


  user_entitlement.initialize();


  user_entitlement.assigned_to = current.variables.Requested_for1;


  user_entitlement.licensed_by = current.variables.Sw_asset1;


  user_entitlement.insert();



Capture.PNG



Please tweak and test as you require.


I change the sw_asset1 >>>> to alm_license table   and used your script   but the new record on user entitlement   did not show data information also.



find_real_file.png


New record


find_real_file.png


Hi Sudaporn,


Would you be able to share your code in here?Also, do you get to see any errors while running your code?  


Regards,Samiul



Sent from Yahoo7 Mail on Android


.footerlinks * a body {font-family:Helvetica, Arial, sans-serif;} h1, h2, h3, h4, h5, h6, p, hr {}.button td {}


This is my code


var user_entitlement = new GlideRecord('alm_entitlement_user');  


  user_entitlement.initialize();  


  user_entitlement.assigned_to=current.variables.Requested_for1;  


  user_entitlement.licensed_by= current.variables.Sw_asset1;  


  user_entitlement.insert();  



find_real_file.png


Are your variable names correct? Variable names are "case-sensitive".



That is,
"current.variables.variable_names" is not same as "current.variables.Variable_Name"