Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Combine formula indicator and contributing indicators in one database view

AndersBGS
Tera Patron
Tera Patron

Hi all,

 

I'm currently working in a reporting governance database view etc., but have come to a struggle. 

 

My requirement is that I would like to combine the formula indicators together with the contributing indicators in a database view or similar. Both the formula indicator and the contributing indicators is placed in the pa_indicators table, where the are combined with the system definitions relationships. 

 

How can I combine this in one view - any good suggestions? Custom table, database view etc?

 

@Mark Manders@Dr Atul G- LNG, @Community Alums, @Tai Vu @Ankur Bawiskar - I know you're highly skilled, so maybe a good suggestion from one of you guys? 

 

Best regards

Anders 

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/

1 ACCEPTED SOLUTION

Hi @AndersBGS 

Not sure if this's late for you. It's been a marathon of long days lately.

There you go!

Business Rule Before Insert/Update/Delete

Order: 9999 (last execution)

Conditions: Type is Formula

 

(function executeRule(current, previous /*null when async*/ ) {

	if(current.operation() === 'delete'){
		deleteContributors(current.getUniqueValue(), '');
		return;
	}

    var contributors = SNC.PAFormula.getIndicators(current.formula.toString());
    deleteContributors(current.getUniqueValue(), contributors);
	if(gs.nil(contributors)){
		return;
	}
	
    contributors = contributors.split(',');
    for (var i in contributors) {
        insertContributors(current.getUniqueValue(), contributors[i]);
    }

})(current, previous);

function insertContributors(formula_indicator, contributor) {
    var gr = new GlideRecord('u_formula_contributor');
    gr.addQuery('u_formula_indicator', formula_indicator);
    gr.addQuery('u_contributing_indicator', contributor);
    gr.query();
    if (gr.hasNext()) {
        return;
    }
    gr.initialize();
    gr.setValue('u_formula_indicator', formula_indicator);
    gr.setValue('u_contributing_indicator', contributor);
    return gr.insert();
}

function deleteContributors(formula_indicator, contributors) {
    var gr = new GlideRecord('u_formula_contributor');
    gr.addQuery('u_formula_indicator', formula_indicator);
    gr.addQuery('u_contributing_indicator', 'NOT IN', contributors);
    gr.query();
    gr.deleteMultiple();
}

 

The reason for choosing a Before rule is primarily due to the delete case. After deletion, we're unable to retrieve associated contributor records.

You may consider having an After rule for Insert/Update and another Before rule for Delete (or Cascade configuration or some other around).

 

 

Cheers,

Tai Vu

 

View solution in original post

5 REPLIES 5

Hi @Tai Vu ,

 

Thank you so much - this works like a charm.

 

Best regards

Anders 

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/