How to determine if at least one user in a list collector variable belongs to a department.

guzman
Giga Guru

Maybe someone can help me out there.

I am currently working on a catalog item that needs to send an approval if any user inside a members list-collector box belongs to the CORP or ASSET department. Otherwise, not approval is needed.

To achieve that, I created a hidden yes/no variable in the form, to then pass the true/false value returned by a AJAX script include, as shown below. Thing is that it always returns ‘false’. Maybe someone can tell me what it is I am doing wrong, or maybe there is a better and easier approach to it.

I am not sure if I need to use the right bucket suffix in the onSubmit client script below.

Script Include:

find_real_file.png

onSubmit Client Script:

find_real_file.png

 

-------------------------------------------------------------------------------------------------------

Thanks,

Juan

 

1 ACCEPTED SOLUTION

Thanks a lot Stefen for the good advice.

I used the gs.log() to track the variable values, and I was able to get the script include returning the correct value. It is a very helpful tool.

The only issue I have now is that the setValue() function does not seem to work when called from within a callback() function inside the onSubmit script. It never updates the cat item variable. It seems to be that it tries to update it after the onSubmit function takes effect.

Maybe someonw out there knows how to update the variable from within the onSubmit client script. I heard that using a Promise should do it, but I am not an advansed Java programmer.

Alternatively, I tried updating the approval_needed var from within the onChange script, but I have problem updating/refreshing its value when adding/removing users on the List Collector variable. I just need to make sure the approval_needed var has a true value, as long as there is a user in the List Collector box who happens to be a member of the CORP or ASSET dept. I noticed that adding users from other departments changes the value to false, which defeats the purpose. 

 

Thanks,

Juan

View solution in original post

5 REPLIES 5

Stefan K_
Tera Expert

When any code is not working, you need to check step by step where it fails (using logging).

For example:
1. Does the client script capture the member variable value correctly? (I suspect you find it does not since "getValue" should be instead "g_form.getValue('members')
2. Does the script include receive the variable value correctly from client script?
3. Does my query find correct records?
4. Does the query go correctly in the IF clause?
5. What does my client script receive as answer?


Thanks a lot Stefen for the good advice.

I used the gs.log() to track the variable values, and I was able to get the script include returning the correct value. It is a very helpful tool.

The only issue I have now is that the setValue() function does not seem to work when called from within a callback() function inside the onSubmit script. It never updates the cat item variable. It seems to be that it tries to update it after the onSubmit function takes effect.

Maybe someonw out there knows how to update the variable from within the onSubmit client script. I heard that using a Promise should do it, but I am not an advansed Java programmer.

Alternatively, I tried updating the approval_needed var from within the onChange script, but I have problem updating/refreshing its value when adding/removing users on the List Collector variable. I just need to make sure the approval_needed var has a true value, as long as there is a user in the List Collector box who happens to be a member of the CORP or ASSET dept. I noticed that adding users from other departments changes the value to false, which defeats the purpose. 

 

Thanks,

Juan

Use onChange instead and any fail you get are likely in the script include returning wrong answer.

"I noticed that adding users from other departments changes the value to false, which defeats the purpose."

Instead what you are doing now I would declare in the beginning of the function "var answer = false". Then in your IF clause set answer = true and return it.

Then also remove that "false" return in the end.

If you still has issues, again the answer is logging, you have to find the step where it goes wrong.

 

 

 

 

Hi   Stefen,

Thanks a lot for your prompt reply.

The issue was resolved as you said. I was able to update the approval_needed variable once I moved it to the onChange client script.

Thanks to you and all other conlleagues who contributed to the solution.

 

Thanks,

Juan