We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Need help with Azure Tags (case sensitive changes)

DaisyB057891995
Tera Expert

Hi team,

 

We have been discovering Azure resources and their tags which were in PascaleCase.

Now, due to a change at Azure, all tag keys are updated to lowercase.

Example:

If key:value was earlier ApplicationName:ServiceNow, it would now be changed to applicationname:ServiceNow

 

If the value of the tag is modified, the SG-Azure delta sync picks it up and updates the "key" in cmdb_key_value to lowercase.

However, if the value of the tag is no changed, the key remains in PascaleCase.

What's the best way to have the case of the key synced to ServiceNow from Azure.

 

2 REPLIES 2

drbob
Tera Contributor

You should be able to fix them with a script. IIRC the tag names are in one table and the values in another but as long as you find the right place and just iterate over the records updating the value with .toLowerCase() they should fix.

 

Considerations...

 

Use .updateMultiple() rather than .update() in a loop

Use gr.setLimit(X) in your query to process X records at a time (depends how many you are fixing but I imagine it's a lot if we're talking about Azure and doing them all at once will overload something

Test it in a lower instance first


I haven't personally used .updateMultiple() but an example is this:

 

 

var grInc = new GlideRecord('incident')
grInc.addQuery('number','IN', 'INC0019002,INC0017892,INC0017869');
grInc.query();
grInc.setValue('state', 8);
grInc.updateMultiple();

 

...so I guess you need...

 

 

var grTagName = new GlideRecord('tag_table')
grTagName.addQuery('name','STARTSWITH', 's');
grTagName.setLimit(100);
grTagName.query();
grTagName.setValue('name', grTagName.name.toLowerCase());
grTagName.updateMultiple();

 

...I didn't check the table not the field name - update "tag_table" and "name" (twice) as appropriate. If it doesn't work then go back to the loop mechanism...

 

var grTagName = new GlideRecord('tag_table')
grTagName.addQuery('name','STARTSWITH', 's');
grTagName.setLimit(100);
grTagName.query();
while(grTagName.next()) {
    grTagName.name = grTagName.name.toLowerCase();
    grTagName.update();
}

 

...and, yes, I reverted to the simpler assignment format - don't think "setValue" is really necessary here.

 

Reference updateMultiple() example and setValue() explanation:

https://www.servicenow.com/community/developer-articles/updatemultiple-operation-optimizing-your-cod...

https://www.servicenow.com/community/developer-forum/how-do-i-use-gr-setvalue/m-p/1419333

drbob
Tera Contributor

Official docs:

https://www.servicenow.com/docs/r/api-reference/server-api-reference/c_GlideRecordAPI.html

I couldn't get it to link to the right section - use your browser search or the nav panel on the right.

It _does_ say use setValue() rather than direct assignment in the updateMultiple() context.