Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Requested For variable and Opened By show alert if different

rconstantino
Mega Sage

Good day,

I have an ask for one catalog item where the Requested For variable (from a variable set) cannot be the same as the person submitting the request.

What is the best way to accomplish this?

Thank you in advance,

Rachel

1 ACCEPTED SOLUTION

maliksneha9
Mega Sage

Hi Rachel,

 

A simple way to enforce this is by using a Catalog Client Script that validates the Requested For variable against the user submitting the request.

Since the user submitting the request is available as g_user.userID, you can compare it with the value selected in the Requested For variable and prevent submission if they are the same.

 

Catalog Client Script:-

function onSubmit() {
var requestedFor = g_form.getValue('requested_for');
var submittedBy = g_user.userID;

if (requestedFor == submittedBy) {
g_form.addErrorMessage("Requested For cannot be the same as the person submitting the request.");
return false;
}

return true;
}

How it Works

- When the user clicks Submit, the script compares the Requested For user with the logged-in user.
- If both are the same, an error message is displayed and the request submission is blocked.

 

Hope this helps!

View solution in original post

2 REPLIES 2

maliksneha9
Mega Sage

Hi Rachel,

 

A simple way to enforce this is by using a Catalog Client Script that validates the Requested For variable against the user submitting the request.

Since the user submitting the request is available as g_user.userID, you can compare it with the value selected in the Requested For variable and prevent submission if they are the same.

 

Catalog Client Script:-

function onSubmit() {
var requestedFor = g_form.getValue('requested_for');
var submittedBy = g_user.userID;

if (requestedFor == submittedBy) {
g_form.addErrorMessage("Requested For cannot be the same as the person submitting the request.");
return false;
}

return true;
}

How it Works

- When the user clicks Submit, the script compares the Requested For user with the logged-in user.
- If both are the same, an error message is displayed and the request submission is blocked.

 

Hope this helps!

Thank you - this works perfectly