New catalog item wanting to populate variable values from a RITM

Bidduam
Tera Guru

I have a catalog item that is being logged that has a list collector and two date variables:

u_user_list

u_start

u_end

 

When this catalog item is submitted (by a team) the flow ultimately sends individually each user in the list collector an email via a event that has a link in it for the user to fill in a new catalog item where the dates in the first catalog item is needed to be auto filled.

 

EG:

Catalog Item 1, has the start and end dates filled in by a team representative to get a user to action something.

 

The user opens the link to Catalog Item 2 and I want to start and end dates to be pre filled on catalog item 2 from the values that were entered into catalog item 1.

 

Help please?

11 REPLIES 11

Ankur Bawiskar
Tera Patron
Tera Patron

@Bidduam 

when you are sending the link in email include the u_start and u_end in the URL as parameters

Then you can use onLoad catalog client script in your 2nd form and get the values from URL parameter

Something like this

1) Use Get Catalog Variables Flow action and then include those in below

/esc?id=sc_cat_item&sys_id=$CAT-SYS-ID$&start=Get Catalog Variable->StartVariable&end=Get Catalog Variable->EndVariable

Then use this onLoad script

function onLoad() {

    try {
        var url = top.location.href;
        var startDate;
        var endDate;
        if (window == null) {
            // for portal
            startDate = new URLSearchParams(url).get("start"); // start here is the url parameter name which we included earlier
            end = new URLSearchParams(url).get("end");  // end here is the url parameter name which we included earlier
            // set the variable values here using g_form.setValue()
        }
    } catch (ex) {
        // for native
        var gUrl = new GlideURL();
        gUrl.setFromCurrent();
        startDate = gUrl.getParam("start");  // start here is the url parameter name which we included earlier
        end = gUrl.getParam("end");  // end here is the url parameter name which we included earlier

        // set the variable values here using g_form.setValue()    
    }
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Ankur Bawiskar 

That concept is an awesome idea thank you, the issue that I have is that 'Catalog Item 1 & 2' will be logged on numerous occasions over time, so is there a way to identify the correct dates from the correct item?

 

Maybe if the user opening the link to catalog item 2 is in the u_user_list then use the dates from that one? Or any open cat item 1 request as the only ones open should have all the same start and end dates in them?

 

Also where are you suggesting I use the get catalog item variables? In the flow for cat item 1?

@Bidduam 

in the flow of 1st catalog item where you are sending link to individual users, there you need to perform the action (Get Catalog Variables, add the URL parameter etc).

Then in 2nd catalog item which is the item included in email of 1st catalog item you write the onLoad script I shared

Consider the 2nd catalog item is directly raised from portal by user without email then the URL won't have that parameter and that doesn't break your script

I hope I was able to explain you and my understanding is correct.

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Ankur Bawiskar 

Sorry I'm a little lost.

In the flow for Catalog Item 1 I already have a "Get Catalog Variables that gets:

u_user_list

u_start

u_end

 

I'm guessing in that flow you are suggesting that I some how add:

/esc?id=sc_cat_item&sys_id=$CAT-SYS-ID$&start=Get Catalog Variable->StartVariable&end=Get Catalog Variable->EndVariable

 

I'm not sure how I add that?

Also the esc?id=sc_cat_item&sys_id=$CAT-SYS-ID$&start=

 

Is that the Catalog sys ID for item 1 or for item 2? I'm guessing item 2 because that's where people are needing to go?

 

I need to send the email otherwise users won't know to go there, they have to wait to be notified