Record Producer Script- trying to set the Opened For user

Rylie Markle
Tera Contributor

I am trying to write a script that will set the Opened For user when a case is submitted. This is what I want it to do: if the logged in user is a member of the specified group, the Opened For on the case should be equal to the Position Manager value (a variable on the record producer). 

Below is what I have before but it keeps telling me a user is not found. I think it has to do with the variable being a Single Line Text Variable and not a reference, but I'm not sure. Is this even possible to accomplish? 

if (gs.getUser().isMemberOf("f65370019f22120047a2d126c42e705c")) {
    current.opened_for = producer.employee_details_position_manager.user;
}

new sn_hr_core.hr_ServicesUtil(current, gs).createCaseFromProducer(producer, cat_item.sys_id);

 

find_real_file.pngfind_real_file.pngfind_real_file.png

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can query sys_user table with the field against which the value is entered

what does the position manager show? user_name or name of the user?

Based on that you can query and get the sys_id

For example I am querying with name field

if (gs.getUser().isMemberOf("f65370019f22120047a2d126c42e705c")) {
    var gr = new GlideRecord("sys_user");
    gr.addQuery("name", producer.employee_details_position_manager);
    gr.query();
    if (gr.next()) {
        current.opened_for = gr.getUniqueValue();
    }
}

new sn_hr_core.hr_ServicesUtil(current, gs).createCaseFromProducer(producer, cat_item.sys_id);

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

4 REPLIES 4

Mark Roethof
Tera Patron
Tera Patron

Hi there,

It looks like your position manager is a single line text? Then dotwalking will never work.

Can you explain functionally where that .user should come from?

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020-2022 ServiceNow Community MVP
2020-2022 ServiceNow Developer MVP

---

LinkedIn
Community article, blog, video list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Yes, it is a single line text. The position manager will populate based on the employee/position that the user chooses when submitting the case. I want the opened for to match what populates in that box, but I'm not sure how because it isn't a reference field. Any suggestions?

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can query sys_user table with the field against which the value is entered

what does the position manager show? user_name or name of the user?

Based on that you can query and get the sys_id

For example I am querying with name field

if (gs.getUser().isMemberOf("f65370019f22120047a2d126c42e705c")) {
    var gr = new GlideRecord("sys_user");
    gr.addQuery("name", producer.employee_details_position_manager);
    gr.query();
    if (gr.next()) {
        current.opened_for = gr.getUniqueValue();
    }
}

new sn_hr_core.hr_ServicesUtil(current, gs).createCaseFromProducer(producer, cat_item.sys_id);

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thank you so much, that makes sense and it worked!