How to force a value onto a variable?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2023 05:06 AM - edited 11-13-2023 05:07 AM
Hi!
I have a Catalog client script that is the following that will be set bellow.
What I want is to check the value of the openedFor field and subjectPerson field and force them to be the logged in user value if selected a specific choice on the selectBoxValue variable.
The issue I am encountering is that it works if:
Both of value in the openedFor and subjectPerson values are different from the logged in user. (It forces the value to be the logged in user)
If the value on the openedFor is the logged in user and the value on the subjectPerson is not, it forces both of them to be the logged in user.
But if the value on the openedFor is not the logged in user and the value of the subjectPerson IS the logged in user, it forces the value of the openedFor to be the logged in user but the value of the subjectPerson clears out and appears blank.
Hopefully I explained correctly and could use some help.
The script will be bellow.
Thank you!
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var openedFor = g_form.getValue('opened_for');
var subjectPerson = g_form.getValue('subject_person');
var selectBoxValue = g_form.getValue('please_choose_the_desired_subcategory');
var user = g_user.userID;
if (selectBoxValue === '2784338e47467d1048bae10e436d43c1_managers') {
g_form.setValue('subject_person', user);
g_form.setValue('opened_for', user);
g_form.addInfoMessage('Please note that you cannot submit payslip for other person than yourself! Please note that the Requested For field was automatically changed!');
g_form.setReadOnly('opened_for', true);
g_form.setReadOnly('subject_person', true);
} else {
g_form.setReadOnly('subject_person', false);
g_form.setReadOnly('opened_for', false);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2023 05:19 AM
Hi @rafas_2703
Your client script code seems correct. There is no mistake in it.
Check if there is any other OnChange client script on the Opened For field that is clearing out the value of Subject Person.
Alternate try:
Write the setValue for Subject Person after the setValue of Opened For.
Thanks!
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up👍✔️
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2023 06:17 AM
Hi @Shubham Singh ,
I did the altearion and the result is the same... and there is no policies / scripts clearing that field.
Any other toughts?