- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2022 07:33 PM
I have create variable with 2 option and below are the scenario i want to achieve.
Scenario 1
When i choose option 1 variable name (u_option1) default the add to cart and order now button already loaded.
Scenario 2
When i choose option 2 variable name (u_option2) the add to cart and order now button must hide.
I attach the screenshot for your reference and is there scripts or option I can do that.
Thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2022 07:48 PM
Hi,
for showing/hiding the add to cart and order now button via script would require DOM manipulation which is not recommended.
if you still require then use this onChange script on that variable
I have shared solution here 2 years ago; enhance it for your requirement
Ensure Isolate Script field is set to False for this client script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if(newValue == 'u_option2'){
// hide
this.document.getElementsByClassName('btn btn-default sc-btn form-control ng-scope')[0].style.display = 'none';
this.document.getElementsByClassName('btn btn-primary btn-block ng-binding ng-scope')[0].style.display = 'none';
}
else{
// show
this.document.getElementsByClassName('btn btn-default sc-btn form-control ng-scope')[0].style.display = '';
this.document.getElementsByClassName('btn btn-primary btn-block ng-binding ng-scope')[0].style.display = '';
}
//Type appropriate comment here, and begin script below
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2022 07:59 PM
Dear Smudge,
thank you for your information and your expertise.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2022 07:48 PM
Hi,
for showing/hiding the add to cart and order now button via script would require DOM manipulation which is not recommended.
if you still require then use this onChange script on that variable
I have shared solution here 2 years ago; enhance it for your requirement
Ensure Isolate Script field is set to False for this client script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if(newValue == 'u_option2'){
// hide
this.document.getElementsByClassName('btn btn-default sc-btn form-control ng-scope')[0].style.display = 'none';
this.document.getElementsByClassName('btn btn-primary btn-block ng-binding ng-scope')[0].style.display = 'none';
}
else{
// show
this.document.getElementsByClassName('btn btn-default sc-btn form-control ng-scope')[0].style.display = '';
this.document.getElementsByClassName('btn btn-primary btn-block ng-binding ng-scope')[0].style.display = '';
}
//Type appropriate comment here, and begin script below
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2022 07:59 PM
Dear Ankur,
I have use your scripts in the catalog scripts and it is working as expected.
thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2022 08:02 PM
Glad to know.
Please mark response helpful as well.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2022 08:03 PM