Hide widgets dependent on 'onchange' value or custom button

walshy
Giga Expert

I have googled my way and searched through the community but I cannot work out how to do the following. 

I have 4 set lists that are 4 widgets (editable table) on a gig form.

I want to have those 4 widgets hidden and only show up when the number of sets is chosen. That answer was going to be in choice field on the form, however I think onchange doesnt work as a UI in the portal. The obvious thing here is if 2 sets is selected, then 2 set lists show up.

I thought about using a button and having the end user click the number of lists they want and then the set lists show that are required.

I thought combining the idea from here: https://serviceportal.io/create-custom-action-buttons-service-portal/

with the idea from here: https://community.servicenow.com/community?id=community_blog&sys_id=e60eea2ddbd0dbc01dcaf3231f961972

would work, but doing that kinda makes my brain explode.  

Below is how it currently looks

find_real_file.pngYou can see why I'd prefer the sets required to be the choice list, it doesn't screw up the page as the buttons do, but hopefully you all get the idea and can point me in the right direction, or tell me I just have to be resigned to having the 4 set lists viewable at all times. 

Thanks for your suggestions. 

 

 

1 ACCEPTED SOLUTION

So guess what happened Josh, the end users decided they didnt want buttons but wanted all 4 set lists to show, plus a 5th list with all of the songs in it. 

It did simplify things for me, but not the full result we were looking at. 

find_real_file.png

The end users are happy, so I must say thank you for all your help!

View solution in original post

9 REPLIES 9

Yes, you'll have to edit the Server Script on the table widget. Line 7 will need to be an If/Else statement instead of just declaring this:

data.showWidget = false; //TO HIDE SET LIST WIDGETS ON PAGE LOAD

Some thoughts on how to do this:
Are the "Set List" records related to the Gig? Like do they have the Gig as a parent record? I would make sure that relationship exists. Then make sure an "Order" field gets populated on the Set List table so you can reference this (this is where we'll get 1-4 and compare it to the options).

Finally you can initially set the data.showWidget variable with a GlideRecord query. You'll query based off if a Set List related to the Gig with the Order which you set in the Options exists.

Here's a look at the basic logic, although you'll have to replace the ALL_CAPS_STUFF with the necessary information. I'm assuming the parent's sys_id probably exists in the url as a parameter. You can get that by using $sp.getParameter() like I've done below.

//PARAMETER_NAME is probably sys_id, but I don't know for sure :)
var parent = $sp.getParameter('PARAMETER_NAME');

var sl = new GlideRecord('SET_LIST_TABLENAME');
sl.addQuery('PARENT_FIELD_NAME', parent);
sl.addQuery('ORDER_FIELD_NAME', options.set_number);
sl.query();
if(sl.next(){
data.showWidget = true;
}else{
data.showWidget = false;
}

Also– If you could please mark my previous answers as Helpful or Correct. It helps me out a ton man!

Thanks,

Josh

Hi Walshy,

Did my above reply answer your question? What issues are you still having?

If I did answer your question, can you please mark it as correct/helpful? It helps me out a ton! Otherwise let me know how I can help.

Thanks,

Josh

Crap!!!

Sorry Josh, haven't had a chance to get back to this, I am going to tackle it later today, also I never got the 'you've been helped' email I have received every other time you have helped me out, ha!

I get what you are saying there. I am hoping I can nut the logic out. 

I have realised I have no relationship between the set list and the Gig table. 

I have the set list songs with columns of set1, set2, set3 and set4 and the widgets filter the results depending on the choice in the other tables. 

So the set lists widgets are just plonked on that gig page with no relationship to the gig number (or sys_id). 

I do need the sets to have a relationship with the gig, as the next gig will obviously need to have a reset of the list so the set lists can be reordered as required. 

I will be back in touch with hopefully a good result!

Thank you so much for your assistance, you've been wonderful. 

So guess what happened Josh, the end users decided they didnt want buttons but wanted all 4 set lists to show, plus a 5th list with all of the songs in it. 

It did simplify things for me, but not the full result we were looking at. 

find_real_file.png

The end users are happy, so I must say thank you for all your help!

Sure thing man, glad to hear you got it all solved!

-Josh