How to auto populate the logged in user details in the catalog item.

Naresh44
Giga Contributor

Hi,

I have created a catalog item with variables requestor, title, location, email id and phone number.

Requirements : 1)  Have to auto populate the  logged in user details by using the requestor variable.

                         2) How to change the visibility of a catalog item to itil

                         3) How to add the approval level 1 as - requestor manager and approval level 2 as the manager of the

application - security team.


Please help me in this regard.

 

Thanks & regards

Naresh Uppu

 

 

 

1 ACCEPTED SOLUTION

Namrata Khabale
Giga Guru

Hey Naresh,

To auto populate the  logged in user details:

Add in default value to that variables : javascript:gs.getUserID()//name of logged in user.

javascript:gs.getUser().getRecord().getValue('phone_number');//phone number

javascript:gs.getUser().getRecord().getValue('location');//location

AS shown in Screen shot:

find_real_file.png

 

TO change the visibility of a catalog item to itil 

GO to Available for

click on Edit

Select itil user.

Screenshot will help you:

 

find_real_file.png

 

 For sending Approval to Requester  Manager create a workflow

Drag and Drop Approval User activity.

In that advance Script write:

var answer=[];

answer.push(current.variables.u_name.manager);

u_name is field name put  your requester filed name.

 

AS shown in screen shot:

find_real_file.png

 

Mark Correct if this solves your issue and also mark  Helpful if you find my response worthy.

 

 

 

 

Thanks,

Namrata

 

 

View solution in original post

6 REPLIES 6

Apeksha Joshi
Kilo Guru

Hi there ,

1) write javascript:gs.getUserName(); in default value of requestor field so that the logged in users name will be populated .same goes with the other variables like email id, location and phone number put the following in each variables defult value:

javascript:gs.getUser().getRecord().getValue('email');

javascript:gs.getUser().getRecord().getValue('phone_number');

javascript:gs.getUser().getRecord().getValue('location');

2) in the related list available for of the catalog item add the role as itil so it will be only visible for itil roles.

3) and to add approvals , click the related link 'add approvals' and add the user and group which you want to send the approval , you can also use workflow for the same.

follow this for approvals: https://docs.servicenow.com/bundle/orlando-it-service-management/page/product/service-catalog-manage...

Mark my answer correct and helpful based on impact.

Regards,

Apeksha

Saurabh singh4
Kilo Guru

Hi Naresh

For Auto population of the above defined Variables you can write an Script Include and call the same Script Include in an OnLoad Catalog Client Script as mentioned below:

 

 

 

Script Include:

 

 

 

var requestor_details = Class.create();

 

requestor_details.prototype = Object.extendsObject(AbstractAjaxProcessor, {

 

 

 

  requestor_info: function() {

 

  var result = this.newItem("result");

 

  var logged_user = gs.getUserID();

 

  var user_detail = new GlideRecord('sys_user');

 

  user_detail.addQuery('sys_id',logged_user);

 

  user_detail.query();

 

  while(user_detail.next())

 

  {

 

  result.setAttribute("user",user_detail.sys_id);

 

  result.setAttribute("phone", user_detail.phone);

 

  result.setAttribute("email",user_detail.email);

 

  result.setAttribute("location",user_detail.location);

 

 

 

  }

 

  },

 

 

 

  type: 'requestor_details'

 

});

 

 

 

find_real_file.png

 

 

 

2) Then you can write an On Load Catalog Client Script wither on your Catalog Item or on the Variable Set to have the variables populated as shown below:

 

 

 

Script:

 

 

 

function onLoad()

 

{

 

  var ga = new GlideAjax("requestor_details");

 

  ga.addParam("sysparm_name","requestor_info");

 

  ga.getXML(ajaxResponse);

 

  function ajaxResponse(serverResponse) {

 

  var result = serverResponse.responseXML.getElementsByTagName("result");

 

  var phone = result[0].getAttribute("phone");

 

  var user = result[0].getAttribute("user");

 

  var email = result[0].getAttribute("email");

 

  var loc = result[0].getAttribute("location");

 

  g_form.setValue('requestor_phone',phone);

 

  g_form.setValue('requestor_name',user);

 

  g_form.setValue('Location_user',loc);

 

  }

 

}

 

 

 

find_real_file.png

 

 

 

Replace your Variable Name appropriately in the Set Value Conditions say for example in place of the variable "Location_user" with your Location Variable.

 

 

 

In a Similar Way you can try for other Variables also.

Please mark my answer correct and helpful , If this helps you in any way thanks in advance

Saurabh

Namrata Khabale
Giga Guru

Hey Naresh,

To auto populate the  logged in user details:

Add in default value to that variables : javascript:gs.getUserID()//name of logged in user.

javascript:gs.getUser().getRecord().getValue('phone_number');//phone number

javascript:gs.getUser().getRecord().getValue('location');//location

AS shown in Screen shot:

find_real_file.png

 

TO change the visibility of a catalog item to itil 

GO to Available for

click on Edit

Select itil user.

Screenshot will help you:

 

find_real_file.png

 

 For sending Approval to Requester  Manager create a workflow

Drag and Drop Approval User activity.

In that advance Script write:

var answer=[];

answer.push(current.variables.u_name.manager);

u_name is field name put  your requester filed name.

 

AS shown in screen shot:

find_real_file.png

 

Mark Correct if this solves your issue and also mark  Helpful if you find my response worthy.

 

 

 

 

Thanks,

Namrata

 

 

Thank you.

Another Requirement : How to add any group manager for the approval ?

Suppose there is an application security team - I need  approval from the manager of this group.

How to do that in the workflow?

please help me.