Highlighted
Trusted Contributor.. Trusted Contributor..
Trusted Contributor..
714 views

Increment of value in a text field

Hi,

can we increase a value stored in a text field by one depending on some condition ?

for example : if we have a field contains "2008" as a value  can this be 2009 or 2008.1 regarding a checked value ?

0 Likes
12 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

Re: Increment of value in a text field

Hello Nadeen,
Hope you are doing well.

Unfortunately I could not understand your explanation. Could you please elaborate?

Thanks a lot!

If you find that this or any other post resolves your issue, please be sure to mark it as an accepted solution. If you are satisfied with anyone’s response please remember to give them a LIKE by clicking on the Thumb and show your appreciation.
0 Likes
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Re: Increment of value in a text field

who sets the data in this text field ? (user\operator manually or automatically)

most likely you need use JS to check data from this field take a digit and perform the necessary arithmetic operations then set result back to this field.

 

0 Likes
Highlighted
Trusted Contributor.. Trusted Contributor..
Trusted Contributor..

Re: Increment of value in a text field

Hello  ALARMus,

the version value will be imported from the CM when the CI chosen . of not ; it will be filled manualy by the user.

depending on current version value ; after running a script we have to increase it by 1 ot (0.1)

 

0 Likes
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Re: Increment of value in a text field

var Strtxt1="2008";
var Strtxt2="2008";
var dig=0;
dig = Number(Strtxt1)+1; Strtxt1=dig; print("1) The result dig is: "+dig); print("2) The result Text from dig is: "+Strtxt1); print("3) The result Text is: "+Strtxt2+1); print("4) The result Text is: "+Strtxt2+"."+1);

And result is:

4) The result Text is: 2008.1
3) The result Text is: 20081
2) The result Text from dig is: 2009
1) The result dig is: 2009

0 Likes
Highlighted
Trusted Contributor.. Trusted Contributor..
Trusted Contributor..

Re: Increment of value in a text field

Hello  ALARMus;

trying to edit the given script as below but it is not updating the required field 

 

var Strtxt1=parseInt(vars.$L_file.ci_version);
var Strtxt2=parseInt(vars.$L_file.ci_version);
var dig=0;

dig = Number(Strtxt1)+1;
Strtxt1=dig;

 function getVersion()
{
if ((vars.$L_file.isversion==1))
{
vars.$L_file.rc_version=Strtxt1;
}
}

function getFix()
{
if ((vars.$L_file.fix==0))
{
vars.$L_file.rc_version=Strtxt2+"."+1;

}
}

 

 

0 Likes
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Re: Increment of value in a text field

parseInt and Number - these functions are similar. I don't think you need use it like: Number(parseInt())

Insert print() in your script to control value of variable and conditions.

Then see what will  you get.

0 Likes
Highlighted
Trusted Contributor.. Trusted Contributor..
Trusted Contributor..

Re: Increment of value in a text field

I removed the parseInt() from the script .

what do you mean by insert print() and where i have to add it ?

 

var ticket = new SCFile("cm3r");
var rc = ticket.doSelect("number=\"C10071\"");
if(rc == RC_SUCCESS)

 


var Strtxt1=(vars.$L_file.ci_version);
var Strtxt2=(vars.$L_file.ci_version);
var dig=0;

dig = Number(Strtxt1)+1;
Strtxt1=dig;

 

function getVersion()
{
if ((vars.$L_file.isversion==1))
{
vars.$L_file.rc_version=Strtxt1;
}
}

function getFix()
{
if ((vars.$L_file.fix==1))
{
vars.$L_file.rc_version=Strtxt2+"."+1;

}
}
ticket.doAction("save");

0 Likes
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Re: Increment of value in a text field

You need to understand what data can be in a text field.

1) this only digits,

2) the text and digits on a particular pattern (for example: ver 360 - ie always 3 characters, a space and three digits)

3) a completely random set of characters in combination with digits

-----------------

About print(), usually to understand what will you get duiring script run - you should put print() operator in script:

Spoiler

var ticket = new SCFile("cm3r");
var rc = ticket.doSelect("number=\"C10071\"");
if(rc == RC_SUCCESS)

var Strtxt1=(vars.$L_file.ci_version);
var Strtxt2=(vars.$L_file.ci_version);
var dig=0;

print("Start value of Strtxt1 = "+Strtxt1);
print("Start value of Strtxt2 = "+Strtxt2);
dig = Number(Strtxt1)+1;
print("Number(Strtxt1) = "+dig);
Strtxt1
=dig;

function getVersion()
{
if ((vars.$L_file.isversion==1))
{
print("isversion is equel 1");
vars.$L_file.rc_version=Strtxt1;}
print("rc.version new values ="+vars.$L_file.rc_version);
}

function getFix()
{
if ((vars.$L_file.fix==1))
print("file.fix is equel 1");
{vars.$L_file.rc_version=Strtxt2+"."+1;
print("rc.version new value = "+vars.$L_file.rc_version);}
}
ticket.doAction("save");

has this code compiled successfully ?

I dont see {} for your if(rc == RC_SUCCESS)

And why did you set function getVersion and getFix ?

0 Likes
Highlighted
Trusted Contributor.. Trusted Contributor..
Trusted Contributor..

Re: Increment of value in a text field

the field is  3) a completely random set of characters in combination with digits

has this code compiled successfully ?

yes it is .

why did you set function getVersion and getFix ?

beacause i have two cases for increment even increase (1) or (0.1)

0 Likes
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Re: Increment of value in a text field

So if the data is a completely random set of characters in combination with digits, how can you find digit you need ?

Or may be there is only one digit wich you need to find ? or may be digit that you need placed only in the end of string ? ...

0 Likes
Highlighted
Trusted Contributor.. Trusted Contributor..
Trusted Contributor..

Re: Increment of value in a text field

Let us go with the first assumption .

the value is full digits like 2008, 10, 100 , ....

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.