The CreatorCon Call for Content is officially open! Get started here.

Scan badge or access card and show sc_task for Requested for

Henrik Jutterst
Tera Guru

This post is for anyone who want to display Catalog Tasks (or any other record) based on information on the user record, like "Employee number" or "Badge number" or "Access Card" stored on the user record.

 

I know this is nothing new, nor advanced, but I made this for myself or anyone who might find this useful.

 

Background

We have facility management in the house where employees go to pickup package arrivals. They scan their badge/access card and the USB-RFI-reader enter the card number in ServiceNow search and hit enter.

We now need to find all sc_task that have to be handed out to the "Requested for" user.

 

The last step in out Flow is to create a task with a notification for the user to pickup their package. Here is how/what we have done to accomplish that.

1 ACCEPTED SOLUTION

Henrik Jutterst
Tera Guru

Solution

Here's all the steps that I went through to create this.

 

 

01-create-badgenumber_field.png

01. Create Badge number on User record

 

 

02-display-badgenumber_field.png

02. Add the field to User record

 

 

03-add-badgenumber_to-a-user.png

03. Give the user a badge number to search for

 

 

04-search-badgenumber_on-a-user.png

04. Search for the badge number and see that you get a hit

 

 

05-create-badgenumber_field_sc_task.png

05. Create the same field on sc_task table

 

 

06-create-business_rule.png

06. Create the Business Rule that insert/copy the value on to the sc_task record for the items that you want. In this case I want it for all sc_task that the user ordered.

 

 

07-create-business_rule_code.png

07. Script for the Business Rule

 

Script in Business Rule here:

(function executeRule(current, previous /*null when async*/ ) {

    //Add user info to record for search 
    if (current.request_item && current.request_item.requested_for) {
        var userGR = new GlideRecord('sys_user');
        if (userGR.get(current.request_item.requested_for)) {
            var empNum = userGR.employee_number;
            var cardNum = userGR.u_badge_number;
            current.u_employee_number = empNum;
            current.u_badge_number = cardNum;
        }
    }

})(current, previous);

 

 

 

 

09-search-badgenumber_on-a-user-2.png

08. Search again. No match ( no records created yet. Also need to index result)

 

 

 

10-sc_task_dictionary.png

09. Add index on sc_task records - Also notice that badge number is shown on sc_task. Go in to form designer and remove the field from the page

 

 

 

10-1-Dictionary Entries _ ServiceNow.png

10. Add Index on Collection row for sc_task

 

 

10-2-Dictionary Entries _ ServiceNow.png

11. Click generate Index and wait.

 

 

11-order-item-for-beth.png

12. Order something for Beth. Approve the Request and make sure that a sc_task is created. 

 

 

12-handout-to-user.png

13. Search for the Badge number "badge123" in the search bar and notice that you can see the active tasks that is requested for the user with that badge number.

 

Done.

 

 

View solution in original post

1 REPLY 1

Henrik Jutterst
Tera Guru

Solution

Here's all the steps that I went through to create this.

 

 

01-create-badgenumber_field.png

01. Create Badge number on User record

 

 

02-display-badgenumber_field.png

02. Add the field to User record

 

 

03-add-badgenumber_to-a-user.png

03. Give the user a badge number to search for

 

 

04-search-badgenumber_on-a-user.png

04. Search for the badge number and see that you get a hit

 

 

05-create-badgenumber_field_sc_task.png

05. Create the same field on sc_task table

 

 

06-create-business_rule.png

06. Create the Business Rule that insert/copy the value on to the sc_task record for the items that you want. In this case I want it for all sc_task that the user ordered.

 

 

07-create-business_rule_code.png

07. Script for the Business Rule

 

Script in Business Rule here:

(function executeRule(current, previous /*null when async*/ ) {

    //Add user info to record for search 
    if (current.request_item && current.request_item.requested_for) {
        var userGR = new GlideRecord('sys_user');
        if (userGR.get(current.request_item.requested_for)) {
            var empNum = userGR.employee_number;
            var cardNum = userGR.u_badge_number;
            current.u_employee_number = empNum;
            current.u_badge_number = cardNum;
        }
    }

})(current, previous);

 

 

 

 

09-search-badgenumber_on-a-user-2.png

08. Search again. No match ( no records created yet. Also need to index result)

 

 

 

10-sc_task_dictionary.png

09. Add index on sc_task records - Also notice that badge number is shown on sc_task. Go in to form designer and remove the field from the page

 

 

 

10-1-Dictionary Entries _ ServiceNow.png

10. Add Index on Collection row for sc_task

 

 

10-2-Dictionary Entries _ ServiceNow.png

11. Click generate Index and wait.

 

 

11-order-item-for-beth.png

12. Order something for Beth. Approve the Request and make sure that a sc_task is created. 

 

 

12-handout-to-user.png

13. Search for the Badge number "badge123" in the search bar and notice that you can see the active tasks that is requested for the user with that badge number.

 

Done.