Need to show 'Add' button only for few states.

archie5
Tera Expert

Need to show 'Add' button only for few states. Currently this Add button on Affected CIs is visible when state is draft, I need to show this for few other states.

This is the condition mentioned in the UI action - RP.isManyToMany() && (new ChangeProposed(parent)).canAddCI() && current.canCreate() && parent.active == true && gs.getProperty('com.snc.task.associate_ci').indexOf(parent.sys_class_name) > -1

I tried adding current.state==-4 etc but that didn't work. Am I missing something?

find_real_file.png

1 ACCEPTED SOLUTION

Most out of the box scripts are marked as SNC at the end of them, and typically there will be a non-SNC version that allows you to extend that script, and "add" to it, or "overwrite" existing functions/variables.

Since you all have altered the OOB Change States, I'm assuming you've also had to alter the State Handler script (ChangeRequestStateHandler which is the extended version of ChangeRequestStateHandlerSNC) in order to allow for the Change to move from State to State.

So I think the correct way to handle this would be to add the new States to the ChangeRequestStateHandler Script Include.

Then create new functions for those states in the ChangeRequest script include that are modeled after the existing isSTATE() functions in the ChangeRequestSNC script include.

Then you can use those functions in the ChangeProposed script include if statement condition.

 

ORRRRR....

I think there may be a quick and dirty way to do it. BUT, it comes with a disclaimer. I'll have to say I don't recommend this, and I don't know if it will break any other functionality. I'll let you decide.

Instead of using the other APIs to check the state, use the GlideRecord object in the ChangeProposed script (this._grChgReq). This way you could input the states as you like with their back-end values. I don't know the back-end values for all of your custom states, but they should be numeric. Here's an example, -5 is the backend value for New and -2 is Scheduled. Add to this:

canAddCI: function() {
		// If it's not a change task, return true and let other conditions decide
		// This has to be done as the Add CI action could be used on all types of tasks
		if (!this._isChangeTask)
			return true;
		
		// If it's a change in the new state, return allow adding of CIs

// 2019-10-30 -- Customizing to allow additonal Change states to add CIs
		if (this._grChgReq.state == '-5' || this._grChgReq.state == '-2'))
			return true;
		
		if (this._log.atLevel(GSLog.DEBUG))
			this._log.debug("[canAddCI] Cannot add CIs to Change Request " + this._grChgReq.number + ":" + this._grChgReq.getUniqueValue());
		
		// In all other cases, don't allow addition of CIs
		return false;
	},

 

If my answer helped you, or solved your issue, please help me out by marking it as Helpful or Correct!

Thanks,

Josh

View solution in original post

17 REPLIES 17

Sorry if I got a bit long-winded in that explanation lol!

The script you want to edit is "ChangeProposed", not ChangeRequestSNC

Replace the canAddCI function with the one I provided.

This:

	canAddCI: function() {
		// If it's not a change task, return true and let other conditions decide
		// This has to be done as the Add CI action could be used on all types of tasks
		if (!this._isChangeTask)
			return true;
		
		// If it's a change in the new state, return allow adding of CIs

// 2019-10-30 -- Customizing to allow additonal Change states to add CIs
		if (this._changeRequest.isNew() || this._changeRequest.isAssess())
			return true;
		
		if (this._log.atLevel(GSLog.DEBUG))
			this._log.debug("[canAddCI] Cannot add CIs to Change Request " + this._grChgReq.number + ":" + this._grChgReq.getUniqueValue());
		
		// In all other cases, don't allow addition of CIs
		return false;
	},

Hey Archie,

Any luck with solution above?

Let me know if you're running into any other issues.

Thanks,

Josh

Hi Josh,

Thanks for your reply.

So I added below line in the function canAddCI.

if (this._changeRequest.isNew() || this._changeRequest.isReview() || this._changeRequest.isPlanninginprogress() || this._changeRequest.isPendingapproval() || this._changeRequest.isScheduled())

The state are, Review, Planning in progress, Pending approval and Scheduled.

It doesn't seem to work. Am I adding it correctly?

 

Archie.

 

Gotcha, so I think "Planning in Progress" and "Pending Approval" are not Out of the Box states, so those functions won't exist. Maybe we can do it the reverse way though where we exclude the States you don't want to have.

 

Here I've excluded the following states: Assess, Authorize, Implement, Closed, and Canceled.

if(!this._changeRequest.isAssess() && !this._changeRequest.isAuthorize() && !this._changeRequest.isImplement() && !this._changeRequest.isClosed() && !this._changeRequest.isCanceled())

Are there any others we DON'T want to show the button for?

So, we have implement to implementation in progress, closed is same, canceled is cancelled and have added completed.