What is "gs.action"?

awright
Kilo Expert

I have been looking around at various servicenow scripts online, and occasionally I stumble upon someone using "gs.action". A search on google, SNC Guru and on the wiki for things along the lines of "servicenow 'gs.action'" only ever shows it being used without ever providing a definitive explanation of what it is and what it can do.

I was wondering if someone could please explain gs.action to me and what it is capable of?

4 REPLIES 4

DrewW
Mega Sage
Mega Sage

Here are its methods and properties.

hashCode
process
getClass
setUniqueField
setType
getActionName
GRList
returnURL
getGlideURI
label
redirect
canRunAction
getRunAt
body
getFromType
isNextRecord
getType
getGotoURL
setRedirectURL
getTarget
values
getOnClick
setCategory
equals
getName
setGRList
getLabel
getRedirectURL
insert
getCondition
wait
getOnClickEscaped
onClickEscaped
isPreviousRecord
ref
actionName
type
getTableName
condition
gotoURL
getActionSysId
getRef
target
getCategory
isRedirect
setGotoURL
previousRecord
onClick
name
glideURI
nextRecord
toString
tableName
fromType
enforceMandatoryOnUpdate
getGRList
redirectURL
get
setRequest
notify
setReturnURL
getUniqueFieldValue
setNoPop
class
notifyAll
setTarget
uniqueFieldValue
isInsert
canPop
getBody
actionSysId
setFromType
runAt
category
getReturnURL
getValues


CapaJC
ServiceNow Employee
ServiceNow Employee

Insert standard caveat/warning here that the methods of undocumented Java classes may change (or be removed entirely) with any given upgrade as code gets refactored. It can be risky to rely on them for business-critical things.


Raymond Ferguso
Tera Contributor

It looks like they may have documented it over the past 8 years.

https://developer.servicenow.com/dev.do#!/reference/api/orlando/server/no-namespace/ActionAPIBoth

As near as I can tell, gs.action is the same as the globally (or top of scope) var "action" that is set under some conditions when the user triggers an action, usually via a button. Most likely, if you have a gs.action, there is probably also an action. And if you are expecting gs.action in a business rule, you are likely throwing a null pointer error when it doesn't.

gs.action.getGlideURI() would be the same thing as action.getGlideURI() in those cases, and when an action is not underway, you would throw a null point back into the invoking rhino / java.

Typically what people seem to want is either new GlideURI() which returns the same thing as gs.action.getGlideURI() or just action within the context of a scripted ui action.

Hi,

Do you know how to avoid null pointer errors when using gs.action in business rules?
Please tell me.