Auto Populate variables on a catalog Item from the cmdb_ci_computer table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-01-2015 12:39 AM
Hello ,
So, the requirement I am working on requires me to list out the CIs assigned to the the current user from a reference field. Upon selecting the item, the "Request For" variable gets populated with the current user's ID which can then be manually changed as well, now based on this user we need to list out the CIs from the cmdb_ci_computer table in the next variable which is also a reference field. Hence, upon selecting the desired CI, the data needs to be auto filled onto a couple of variables on the catalog item (like manufacturer, serial number etc.). These variables are a part of a variable set.
If no records are found in the cmdb_ci_computer table for the user, we need to display an info and list out amset of variables that need to be manually filled.
Kindly guide how this can be achieved.
Best Regards,
Urmilla Dhar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-01-2015 12:45 AM
Hi Urmilla,
For the first requirement i.e "now based on this user we need to list out the CIs from the cmdb_ci_computer table in the next variable which is also a reference field." you can use reference qualifier to restrict the CI's choice based on the user. More info here.
http://wiki.servicenow.com/index.php?title=Reference_Qualifiers#gsc.tab=0
For the next requirement i.e "Hence, upon selecting the desired CI, the data needs to be auto filled onto a couple of variables on the catalog item (like manufacturer, serial number etc.)." This requirement can be achieved by using getReference(object). Please refer the example "Set location to user" OOB client script on incident table for more info.
Please let me know if you have any questions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2015 11:39 PM
Hi Pradeep,
I was able to perform the first activity as well as have written the client script for setting the values on the variables however just wanted to enquire what would be the best way to populate the reference fields as for example Manufacturer is a reference field and once we setValue using GetReference we get the sys id and not the display value.
Regards,
Urmilla

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2015 11:44 PM
Hi Urmilla,
Thanks for the update. Yes you will get the sys_id but however if you set the value to the reference field it should set the display value.
If you want to set the Display value to string field in that case you have to do the GlideAjax from the client script and return the value.
Please let me know if you have any questions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-06-2015 04:04 AM
Hello Pradeep,
Thanks was able to complete the client script to populate the value for all the reference fields aswell.
There is one other scenario that I need to validate. For example, if there are no CIs assigned to a particular user , we need to check and display a message to the user informing the same and make the fields that get auto populated,editable so that the user can enter the values manually.
Hence, we need to check if the object.query function returns no records for a user and display the message. Would appreciate your guidance.
I am new to ServiceNow development and hence pardon me if my questions are a little vague.
Thanks,
Urmilla