How does this dynamic annotation work?

aaron47
Mega Guru

Hello,

This relates to the change_request form.

On my Paris developer instance, I can see there is an annotation that has this text:

${new ChangeRequestDateMessage(current).getDateMsg()}

 

find_real_file.png

 

Which is rendered as follows:

find_real_file.png

 

 

I was unable to find any reference to this on the internet.  Infact I couldn't find anything about dynamic annotations which I didn't realise was possible until now.

I am trying to debug this as it is no working on my company's instance, the text comes out empty:

find_real_file.png

 

Does anyone have some tips with how to debug this?

1 ACCEPTED SOLUTION

AnirudhKumar
Mega Sage
Mega Sage

ChangeRequestDateMessage is the name of a script include.

Go to the Script include table and search for it.

 

Once you find it, you should look for the specific function with name getDateMsg

View solution in original post

6 REPLIES 6

AnirudhKumar
Mega Sage
Mega Sage

ChangeRequestDateMessage is the name of a script include.

Go to the Script include table and search for it.

 

Once you find it, you should look for the specific function with name getDateMsg

Thank you.  It turned out I didn't have this script include as part of my instance for some reason.

 

FYI:

https://[instance]/nav_to.do?uri=sys_script_include.do?sys_id=c59c8722677222004792adab9485ef51

Hi, 

I'm interested in this solution, and dynamic annotation. I also don't have that script include on my instance. Are you able to post its contents?

Tim

not OP but here u go

var ChangeRequestDateMessage = Class.create();

ChangeRequestDateMessage.prototype = {
	
    initialize: function(_gr) {
        this.gr = _gr;
    },
	
    /**
     * Gets the description message for the change request planned start/end date based on the state.
     * 
     * @returns the message to display or empty string if not applicable
     */
    getDateMsg: function() {
        if (!this.gr)
            return "";

		var state = this.gr.getValue("state") - 0;
		if (state === 4) // canceled
			state = this._getPreviousState();
        return this._getDateMessage(state);
    },

	_getDateMessage: function(state) {
		var td = GlideTableDescriptor.get("change_request");
		var startElement = td.getElementDescriptor("start_date");
		var startLabel = startElement ? startElement.getLabel() : gs.getMessage("Planned start date");
		var endElement = td.getElementDescriptor("end_date");
		var endLabel = endElement ? endElement.getLabel() : gs.getMessage("Planned end date");
		switch(state.toString()){
			case "-5": // new
			case "-4": // assess
			case "-3": // authorize
				return gs.getMessage("{0} and {1} are the requested change window", [startLabel, endLabel]);
			case "-2": // scheduled
			case "-1": // implement
			case "0": // review
			case "3": // closed
				return gs.getMessage("{0} and {1} are the approved change window", [startLabel, endLabel]);
			default:
				return "";
		}
	},

	_getPreviousState: function() {
		var gr = new GlideRecord("sys_history_line");
		gr.addEncodedQuery("field=state^set.id=" + this.gr.sys_id + "^set.table=change_request^ORDERBYDESCupdate");
		gr.query();
		if (gr.next())
			return gr.getValue("old_value");
	},

    type: "ChangeRequestDateMessage"
};