Setting Requested For With an Item Variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2013 08:20 PM
I am having an issue setting the requested for field from an Item variable and was wondering if anyone had a solution. We would like to set request.requested_for field to the value of a variable in a requested item. This way, the Service desk can request on behalf of other users, via a mandatory field right on the item. (As opposed to using the request for widget) The name of the variable is open_for
I tried doing this with the following after business rule.
setOpenFor();
function setOpenFor(){
var req_for = new GlideRecord('sc_request');
req_for.get(current.request);
req_for.requested_for = current.variables.open_for;
req_for.update();
}
This worked, except it generates the following error
Duplicate entry '9634b55ad99445009c808723f662dd62' for key 'PRIMARY'
Then I tried to set it through a Catalog client script via the following (onchange for the open_for variable)
function onChange(control, oldValue, newValue, isLoading) {
if (!isLoading) {
var userid = g_user.userName;
var newid = g_form.getValue('open_for');
var cart = new GlideRecord('sc_cart');
cart.addQuery('user.user_name', userid);
cart.query();
if (cart.next()) {
cart.requested_for = newid;
cart.update();
}
}
}
This also worked but only for admins. I tried changing the ACL for sc_cart to allow ITIL users to read write, but it seems to be ignoring the rule.
Any help would be greatly appreciated.
Thanks for your time,
Randy
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2013 01:06 PM
This question is unanswered in the community, check the link:
Referencing "Request For" While Ordering a Catalog Item
Though, I was able to find a workaround on community itself. If a user has 'data_lookup_admin' role then the script will work as expected.
Check the following link for more info:
Catalog Client Script not Working
For me, it is still open as I want the script to work for the end users who do not have any role.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2013 09:35 PM
Randy,
Try doing this from the REQ through a before Business Rule. I have detailed the business rule below:
Name: Populate Requested for Field
Table: Request [sc_request]
Active: true
When: before
Insert: true
Condition: [leave blank]
Script:
var grRITM = new GlideRecord('sc_req_item');
grRITM.addQuery('request', current.sys_id);
grRITM.query();
while (grRITM.next()) {
if (!JSUtil.nil(grRITM.variables.open_for)) {
current.requested_for = grRITM.variables.open_for;
}
}
Hope this helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2015 08:49 AM
Thanks so much!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2015 11:03 AM
Dear,
it is absolutely workable solution.
Thank you very much.