Looping through private data and adding to file name suffix

Post Reply
cwswitch
Member
Posts: 78
Joined: Fri Feb 24, 2017 12:25 am

Looping through private data and adding to file name suffix

Post by cwswitch »

Hi,

I have files arriving at a rename which contain private data that I want to add to the filename.

The private data will be Key 01, Value 01 to Key nn, Value nn (key name and the value they hold are the same so Key 88 would be value 88).

A job may have Keys 01 and 03, another job may have keys 04 and 05, there may be another job that only has key 02.

These jobs would end up being called

JobName-01-03
JobName-04-05
JobName-02

I'm looking to write a For Loop something like the below. This is riddled with errors and I'm working on it now, I welcome tips

Code: Select all

//Output string
var OSTRING = 0;

//Loop string
var LSTRING = 0;

//Private Data Key 
PDKEY1 = '[Job.PrivateData:Key="';
PDKEY2 = LSTRING
PDKEY3 = '"]'

//Check String
var CSTRING = 'PDKEY1'+PDKEY2+'PDKEY3';		 
		 
//Incementor
for (var i=0; i < 99; i=i+1)
LSTRING = i;
	if (LSTRING <= 9) {
	LSTRING = '0' + LSTRING;
	//Private Data Key 
PDKEY1 = '[Job.PrivateData:Key="';
PDKEY2 = LSTRING
PDKEY3 = '"]'
	//Check String
var CSTRING = 'PDKEY1'+PDKEY2+'PDKEY3';	
}
	
	if (LSTRING == CSTRING) {
	OSTRING = OSTRING+'-'+LSTRING;
}
{

}
OSTRING
Which produces nothing for OSTRING

curiously, CSTRING gives

Code: Select all

_0DNHT_JobNamePDKEY10PDKEY3
- so not quite there yet
Last edited by cwswitch on Thu Feb 14, 2019 10:09 pm, edited 1 time in total.
r.zegwaard
Member
Posts: 93
Joined: Fri Jul 08, 2011 10:31 am
Location: The Netherlands

Re: Looping through private data and adding to file name suffix

Post by r.zegwaard »

This should do the trick :)

Code: Select all

// get a list of all privatedata-tags
pdkList = job.getPrivateDataTags();
// create an empty array for found values
valueList=[];

// Itterate privatedata key's
for (i=0;i<pdkList.length;i++) {
	
	// Check if it starts with "Key "
	if(pdkList[i].find('Key ') == 0){ 
		// Add value to valueList
		valueList.push(job.getPrivateData(pdkList[i]));
	}
	
}

result = "-" + valueList.join("-");
result;
cwswitch
Member
Posts: 78
Joined: Fri Feb 24, 2017 12:25 am

Re: Looping through private data and adding to file name suffix

Post by cwswitch »

Holy shit

Thanks!!!

As my script was getting longer and worse, you came in with a nice tidy solution :lol:

I have so much to learn!
Post Reply