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 ?

  • Hello Nadeen,
    Hope you are doing well.

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

    Thanks a lot!

  • 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.

     

  • 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)

     

  • 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

  • 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;

    }
    }

     

     

  • 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.

  • 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");

  • 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:

    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 ?

  • 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)

  • 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 ? ...