RP + current

caucau
Kilo Explorer

Hey there,

 

I'm having a problem with specifying a condition for a UI action (bottom list button and choice list).

 

If the condition equals !RP.isRelatedList(), then the UI action correctly does not display on related lists. If the condition equals current.u_state == 'Created', then when selecting some items of the list via checkboxes, clicking on the   "Actions on selected rows..." triggers succesfully that condition and if, say, i chose 5 items from which 2 are in state created, it says "UI action (2 of 5)" and after confirmation sends only those records satisfying that condition. So far so good.

 

But.

 

When the condition equals: !RP.isRelatedList() && current.u_state == 'Created', the relatedList condition stops working (the UI action is displayed on related lists). The condition for restricting states on a list works correct.

 

On ServiceNow wiki is a note, that when using "current"   object where it is not defined it is ignored. My assumption is that not only the single statement is ignored, but the whole condition field? So that current.u_state causes the RP condition to be ignored? How to solve this? Should I refactor these conditions to a script include and call it in the condition field?

 

Thx for help,

 

Jirka N.

14 REPLIES 14

Ah, I see now.


Unfortunately, there's not a way to do that in a button, only a list action as you've already discovered.



You could do the following and get close, however.


1. use RP.getEncodedQuery() and parse the query to see if "u_state" is present, and the "Created" records are potentially present (e.g. NOT explicitly excluded from the current filter parameter)


2. In the UI Action script, check each record to see if it's "Created" and only apply the script to them.


3. Add an info message for the skipped records



If that doesn't work, you could submit an enhancement request. 🙂


Ok, thx for proposition, but in comparison to an easy client jquery script removing the buttons on a concrete form, this is just not seems worth the effort ..


domaners
Kilo Guru

Hi JiÅ™í­,



Yeah it looks like you might need a script include to test this as it may be the lack of a current object when running your query is causing a script error to occur, wiping out the RP query in the process. Have you logged a Hi ticket for this?


But will I have the RP object available in a separate script include?



And no, I have not logged a ticket for this.. Should I? And where?



Thx for reply.


No, the RP variable probably won't be available in the Script Include, but you can pass it over in the function call. Set your UI Action conditiion to something like this:



checkCreated(RP.isRelatedList())



Then create a new Script Include and set the logic in there:



function checkCreated(isRelated) {


    if(!isRelated && current) {


          if(current.u_state == 'Created') {


                  return true;


          } else {


                  return false;


    } else {


          return false;


    }


}