- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2018 02:22 AM
Hi! I am trying to set up a basic version management function.
I have a working approval workflow but every time a record is approved, I would like to increase the version number of the record by 0.1. It should also be possible to manually set the version to 1.0, 2.0 and so on when the record is finalized.
I have found several articles here in the community, but no one that fits my purpose. The main problem I have is to increment by 0.1 and not by 1. Therefore I have tried to have an Integer field (hidden) that increases by 1 every time the approval workflow starts, and that is working as I expected (before update BR).
(function executeRule(current, previous /*null when async*/) {
// Increases update count
var number = current.u_update_count;
number++;
current.u_update_count = number;
})(current, previous);
The second part is to convert this to a 0.1 increase on my version field, AND to be able to manually enter a version number and if that happens re-set the Integer counter to correspond to whatever I manually enter in the version field.
I really need some help with this.
Best regards
//Per
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2018 06:48 AM
I´ll answer this one myself:
To anyone that may have use of this, I removed the integer field and just used one string field (oob). So, basically, all logic is done by one BR.
(function executeRule(current, previous /*null when async*/) {
// Increases version number every time the record is updated via the revision process
// When service is published to the service catalog, set the version number to the next corresponding integer.
var ver = current.version;
var verAdj = ver*10; //multiply by 10 so it can be handled by ++ method.
if (current.u_state.changesTo("active")) {
var newVer = parseInt(verAdj);
newVer++; //add 1
current.version = newVer/10; //divide by 10 so I get back the version number.
}
if (current.portfolio_status.changesTo("catalog")) {
var verPub = parseInt(current.version); //convert to integer
gs.addInfoMessage(verPub);
verPub++; //add 1
current.version = verPub + '.0'; //set new version number, integer.
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2018 06:48 AM
I´ll answer this one myself:
To anyone that may have use of this, I removed the integer field and just used one string field (oob). So, basically, all logic is done by one BR.
(function executeRule(current, previous /*null when async*/) {
// Increases version number every time the record is updated via the revision process
// When service is published to the service catalog, set the version number to the next corresponding integer.
var ver = current.version;
var verAdj = ver*10; //multiply by 10 so it can be handled by ++ method.
if (current.u_state.changesTo("active")) {
var newVer = parseInt(verAdj);
newVer++; //add 1
current.version = newVer/10; //divide by 10 so I get back the version number.
}
if (current.portfolio_status.changesTo("catalog")) {
var verPub = parseInt(current.version); //convert to integer
gs.addInfoMessage(verPub);
verPub++; //add 1
current.version = verPub + '.0'; //set new version number, integer.
}
})(current, previous);