Topic
  • 35 replies
  • Latest Post - ‏2015-07-14T11:07:32Z by Mike.Scharnow
jrhaighl3msuk
jrhaighl3msuk
7 Posts

Pinned topic Creating a Change Request through CSAPI

‏2013-11-04T15:32:05Z | bulk change creation csapi request

Is there any way to bulk or automatically create a series of CR's through the CSAPI? I need to create approx a hundred or so CR's from data supplied by another company (so I can't DCM it). I wondered if I got the data I required from their CM system in a text/excel report, if I could automate the import of the data into my System (Change 5.2/Synergy 7.1).

Does anyone have any example code to do this that I could modify to my own requirement?

  • Mike.Scharnow
    Mike.Scharnow
    70 Posts

    Re: Creating a Change Request through CSAPI

    ‏2013-11-04T16:18:37Z  

    Yes, that's possible.

    I don't have any example code since this functionality is spread among several files in our environment, but the following might help you in creating your own code. For a regular update, you would do something like this:

    • use the Perl API. It is quite well documented with examples. Navigate to the help pages in the admin surface, there you find the information you need
    • programs will start with logging into the database (commands setUpConnection, new ChangeSynergy::apiUser, Login)
    • you will use an existing Perl module to help you read your input file (e.g. Spreadsheet::XLSX) and you will ask your supplier to send the data in a defined format (e.g. problem_number is always column 1 or perhaps you define a supplier_problem_number) and read in all attributes of all rows into a hash for easy access.
    • for each retrieved row, you will make a query to see whether it already exists in your DB (command "QueryData" in combination with getDataSize or "GetCRData")
    • Then for each attribute you will make an update if the attributes are not identical (setValue) and do a ModifyCR
    • If the CR does not yet exist, you will submit a new CR ("SubmitCRData", setValue for each attribute, "SubmitCR"). Make sure that all attributes that you want to import automatically are painted on your submit form

     

    Hope this helps -- if you have concrete questions about a command or the general way of working, just ask.

    Mike Scharnow
    Consultant Application Life Cycle Managament
    IT-QBase GmbH

  • jrhaighl3msuk
    jrhaighl3msuk
    7 Posts

    Re: Creating a Change Request through CSAPI

    ‏2013-11-05T12:37:29Z  

    Yes, that's possible.

    I don't have any example code since this functionality is spread among several files in our environment, but the following might help you in creating your own code. For a regular update, you would do something like this:

    • use the Perl API. It is quite well documented with examples. Navigate to the help pages in the admin surface, there you find the information you need
    • programs will start with logging into the database (commands setUpConnection, new ChangeSynergy::apiUser, Login)
    • you will use an existing Perl module to help you read your input file (e.g. Spreadsheet::XLSX) and you will ask your supplier to send the data in a defined format (e.g. problem_number is always column 1 or perhaps you define a supplier_problem_number) and read in all attributes of all rows into a hash for easy access.
    • for each retrieved row, you will make a query to see whether it already exists in your DB (command "QueryData" in combination with getDataSize or "GetCRData")
    • Then for each attribute you will make an update if the attributes are not identical (setValue) and do a ModifyCR
    • If the CR does not yet exist, you will submit a new CR ("SubmitCRData", setValue for each attribute, "SubmitCR"). Make sure that all attributes that you want to import automatically are painted on your submit form

     

    Hope this helps -- if you have concrete questions about a command or the general way of working, just ask.

    Mike Scharnow
    Consultant Application Life Cycle Managament
    IT-QBase GmbH

    Thank you for that Mike,

    It'll probably be a few days until I get a chance to try it out, I may dip back for some additional information if i may.

    Regards

     

    Jonathan

  • mahesh12345
    mahesh12345
    8 Posts

    How to change/set default lifecycle to custom defined life cycle using csapi

    ‏2013-11-08T13:17:43Z  

    Thank you for that Mike,

    It'll probably be a few days until I get a chance to try it out, I may dip back for some additional information if i may.

    Regards

     

    Jonathan

    Hi,

                         When i was trying to create new CR using SubmitCRData ,csapi module not allowing me to set the values for few attributes ( e.g., release , who_found ) and it is throwing below problem:

    Could not find specified value 'release' at C:/Perl64/lib/ChangeSynergy/apiObjectVector.pm line 286.

    After some analysis ,I suspect csapi pointing to Default Lifecycle instead of Patch Lifecycle (Customized Lifecycle).

    patch Lifecycle contains the 'release' attribute whereas default Lifecycle not contains the 'release' attribute.

    So could anyone suggest me how to set/change the 'default lifecycle' to 'custom defined lifecycle' by using csapi.

     

    Regards

    Mahesh

     

     

  • mahesh12345
    mahesh12345
    8 Posts

    How to change/set default lifecycle to custom defined life cycle using csapi

    ‏2013-11-09T06:32:54Z  

    Yes, that's possible.

    I don't have any example code since this functionality is spread among several files in our environment, but the following might help you in creating your own code. For a regular update, you would do something like this:

    • use the Perl API. It is quite well documented with examples. Navigate to the help pages in the admin surface, there you find the information you need
    • programs will start with logging into the database (commands setUpConnection, new ChangeSynergy::apiUser, Login)
    • you will use an existing Perl module to help you read your input file (e.g. Spreadsheet::XLSX) and you will ask your supplier to send the data in a defined format (e.g. problem_number is always column 1 or perhaps you define a supplier_problem_number) and read in all attributes of all rows into a hash for easy access.
    • for each retrieved row, you will make a query to see whether it already exists in your DB (command "QueryData" in combination with getDataSize or "GetCRData")
    • Then for each attribute you will make an update if the attributes are not identical (setValue) and do a ModifyCR
    • If the CR does not yet exist, you will submit a new CR ("SubmitCRData", setValue for each attribute, "SubmitCR"). Make sure that all attributes that you want to import automatically are painted on your submit form

     

    Hope this helps -- if you have concrete questions about a command or the general way of working, just ask.

    Mike Scharnow
    Consultant Application Life Cycle Managament
    IT-QBase GmbH

    Hi Mike,

                   When i was trying to create new CR using SubmitCRData ,csapi module not allowing me to set the values for few attributes ( e.g., release , who_found ) and it is throwing below problem:

    Could not find specified value 'release' at C:/Perl64/lib/ChangeSynergy/apiObjectVector.pm line 286.

    After some analysis ,I suspect csapi pointing to Default Lifecycle instead of Patch Lifecycle (Customized Lifecycle).

    patch Lifecycle contains the 'release' attribute whereas default Lifecycle not contains the 'release' attribute.

    Suggest me how to set/change the 'default lifecycle' to 'custom defined lifecycle' by using csapi.

     

    Regards

    Mahesh

  • Mike.Scharnow
    Mike.Scharnow
    70 Posts

    Re: How to change/set default lifecycle to custom defined life cycle using csapi

    ‏2013-11-09T08:22:53Z  

    Hi Mike,

                   When i was trying to create new CR using SubmitCRData ,csapi module not allowing me to set the values for few attributes ( e.g., release , who_found ) and it is throwing below problem:

    Could not find specified value 'release' at C:/Perl64/lib/ChangeSynergy/apiObjectVector.pm line 286.

    After some analysis ,I suspect csapi pointing to Default Lifecycle instead of Patch Lifecycle (Customized Lifecycle).

    patch Lifecycle contains the 'release' attribute whereas default Lifecycle not contains the 'release' attribute.

    Suggest me how to set/change the 'default lifecycle' to 'custom defined lifecycle' by using csapi.

     

    Regards

    Mahesh

    Hello Mahesh,

    when you have several life cycles installed at the same time in one instance, you should have several start states, let's assume entered_cr and entered_problem, 

    The Syntax for creating a CR is

    $ tmp = $csapi-> SubmitCRData ( $aUser, "START_HERE2entered_cr" )

    So by changing the value for the start state you should automatically be in the correct life cycle.

    Another reason for this error might be that you did not paint "release" on the "Enter CR" form.

    Hope this helps

    Mike

  • mahesh12345
    mahesh12345
    8 Posts

    Re: Problem with Modify the CR Data using csapi

    ‏2013-11-13T04:42:37Z  

    Hello Mahesh,

    when you have several life cycles installed at the same time in one instance, you should have several start states, let's assume entered_cr and entered_problem, 

    The Syntax for creating a CR is

    $ tmp = $csapi-> SubmitCRData ( $aUser, "START_HERE2entered_cr" )

    So by changing the value for the start state you should automatically be in the correct life cycle.

    Another reason for this error might be that you did not paint "release" on the "Enter CR" form.

    Hope this helps

    Mike

    Hi Mike,

       Thanks for your quick reply, your suggested solution helps me a lot.

    I am facing one more problem at the time of modifying the CR.

    When i was trying to modify the CR by using below api calls but i am facing below issue:

    Code :

    my $tmp = $csapi->GetCRData($aUser, "problem_number", "crstatus");
    $tmp->getDataObjectByName("crstatus")->setValue("Patch_test");

    $csapi->ModifyCR($aUser, $tmp);

    Issue :

    The fault code: 4
    The fault string: CsAPI: CRModify: Failed to modify CR data

    Can you share your suggestions or solution on this.

    Also let me how to retrieve/query the child CR information of a given parent CR.

     

    Thanks

    Mahesh

     

  • Mike.Scharnow
    Mike.Scharnow
    70 Posts

    Re: Problem with Modify the CR Data using csapi

    ‏2013-11-13T09:55:21Z  

    Hi Mike,

       Thanks for your quick reply, your suggested solution helps me a lot.

    I am facing one more problem at the time of modifying the CR.

    When i was trying to modify the CR by using below api calls but i am facing below issue:

    Code :

    my $tmp = $csapi->GetCRData($aUser, "problem_number", "crstatus");
    $tmp->getDataObjectByName("crstatus")->setValue("Patch_test");

    $csapi->ModifyCR($aUser, $tmp);

    Issue :

    The fault code: 4
    The fault string: CsAPI: CRModify: Failed to modify CR data

    Can you share your suggestions or solution on this.

    Also let me how to retrieve/query the child CR information of a given parent CR.

     

    Thanks

    Mahesh

     

    Hi Mahesh,

    crstatus:

    Change does not allow you to manipulate the status directly (as in the GUI surface). You will need to make a transition from the current state to your destination state. Either you do this by using allowed transitions, or you must log in as an administrator, this would be the equivalent of  an "Admin Transition" in the gui.

    Check the csapi documentation regarding

    my $tmpstr = $csapi->TransitionCR($aUser, $tmp2);
    

    for examples.

     

    child information:

    First you need the name of the relation. In your case this should be "child" (corresponds to the attribute name that you defined in Change).

    Then you need the direction. It is either "has_<relation>" or "is_<relation>_of". This direction is used as a function for the query. So, to get the children of problem 12345, you would make a query like 

    my $tmp = $csapi->QueryData($aUser, "Basic Summary", "is_child_of(cr('12345')", undef, undef, undef);
    

    or equivalently

    my $tmp = $csapi->QueryData($aUser, "Basic Summary", "(is_child_of(problem_number='12345') and (cvtype='problem')", undef, undef, undef);
    

     

    hope this helps,

    BR,
    Mike

  • mahesh12345
    mahesh12345
    8 Posts

    Re: Problem with Modify the CR Data using csapi

    ‏2013-11-13T13:38:44Z  

    Hi Mahesh,

    crstatus:

    Change does not allow you to manipulate the status directly (as in the GUI surface). You will need to make a transition from the current state to your destination state. Either you do this by using allowed transitions, or you must log in as an administrator, this would be the equivalent of  an "Admin Transition" in the gui.

    Check the csapi documentation regarding

    <pre style="color: rgb(0, 0, 0);">my $tmpstr = $csapi->TransitionCR($aUser, $tmp2); </pre>

    for examples.

     

    child information:

    First you need the name of the relation. In your case this should be "child" (corresponds to the attribute name that you defined in Change).

    Then you need the direction. It is either "has_<relation>" or "is_<relation>_of". This direction is used as a function for the query. So, to get the children of problem 12345, you would make a query like 

    <pre style="color: rgb(0, 0, 0);">my $tmp = $csapi->QueryData($aUser, "Basic Summary", "is_child_of(cr('12345')", undef, undef, undef); </pre>

    or equivalently

    <pre style="color: rgb(0, 0, 0);">my $tmp = $csapi->QueryData($aUser, "Basic Summary", "(is_child_of(problem_number='12345') and (cvtype='problem')", undef, undef, undef); </pre>

     

    hope this helps,

    BR,
    Mike

    Hi Mike,

              Once again thanks for your prompt reply...

    As per your suggestion ,I have tried the 1st scenario (crstatus) and it was working fine.

    Also i have tried 2nd scenario (fetch child information), it was not working as expected.

    Used Code :

    my $results = $csapi->QueryData($aUser, "Basic Summary", "is_child_of(cr('3997')", undef, undef, undef);
    print "Size : " . $results->getDataSize() . "\n";

    Here getDataSize() method returns Size is '0'.

    Whereas Parent CR - 3997 contains/associated with 3 child CR's (relation is : patch_dev_child ) and i am expecting getDataSize() would be '3'.

    Could you please suggest me, what might be wrong and how to get the child patch details ?

     

    Regards

    Mahesh

  • Mike.Scharnow
    Mike.Scharnow
    70 Posts

    Re: Problem with Modify the CR Data using csapi

    ‏2013-11-13T14:03:30Z  

    Hi Mike,

              Once again thanks for your prompt reply...

    As per your suggestion ,I have tried the 1st scenario (crstatus) and it was working fine.

    Also i have tried 2nd scenario (fetch child information), it was not working as expected.

    Used Code :

    my $results = $csapi->QueryData($aUser, "Basic Summary", "is_child_of(cr('3997')", undef, undef, undef);
    print "Size : " . $results->getDataSize() . "\n";

    Here getDataSize() method returns Size is '0'.

    Whereas Parent CR - 3997 contains/associated with 3 child CR's (relation is : patch_dev_child ) and i am expecting getDataSize() would be '3'.

    Could you please suggest me, what might be wrong and how to get the child patch details ?

     

    Regards

    Mahesh

    Well, if your relation is patch_dev_child, did you try the query with "is_patch_dev_child_of()"?

     

    BR,

    Mike

  • mahesh12345
    mahesh12345
    8 Posts

    Re: Problem with Modify the CR Data using csapi

    ‏2013-11-13T15:32:24Z  

    Well, if your relation is patch_dev_child, did you try the query with "is_patch_dev_child_of()"?

     

    BR,

    Mike

    As per your suggestion ,I have tried with below code, still i am facing same problem ..

    my $results = $csapi->QueryData($aUser, "Basic Summary", "is_patch_dev_child_of(cr('3997')", undef, undef, undef);

    Result : DataSize : 0

     

    Regards

    Mahesh

     

  • Mike.Scharnow
    Mike.Scharnow
    70 Posts

    Re: Problem with Modify the CR Data using csapi

    ‏2013-11-13T15:41:56Z  

    As per your suggestion ,I have tried with below code, still i am facing same problem ..

    my $results = $csapi->QueryData($aUser, "Basic Summary", "is_patch_dev_child_of(cr('3997')", undef, undef, undef);

    Result : DataSize : 0

     

    Regards

    Mahesh

     

    That's strange. Well, now I see that there is a syntax error in the code I sent and you used (only one bracket is closed), but I assume you already tried this and perhaps the equivalent expression?

    When you log into the Change GUI you also have the possibility to create queries, you need not write / change a perl script all the time. I would suggest you try out combinations of "has_<relation>" and "is_<relation>_of". For example, you can write "is_patch_dev_child_of (type='problem')" to see whether there are any patch_dev_childs at all, from there on you can change your query until it works.

    HTH,

    Mike

     

  • mahesh12345
    mahesh12345
    8 Posts

    Re: Problem with Modify the CR Data using csapi

    ‏2013-11-13T15:58:57Z  

    That's strange. Well, now I see that there is a syntax error in the code I sent and you used (only one bracket is closed), but I assume you already tried this and perhaps the equivalent expression?

    When you log into the Change GUI you also have the possibility to create queries, you need not write / change a perl script all the time. I would suggest you try out combinations of "has_<relation>" and "is_<relation>_of". For example, you can write "is_patch_dev_child_of (type='problem')" to see whether there are any patch_dev_childs at all, from there on you can change your query until it works.

    HTH,

    Mike

     

    Great, It is working.

    I have tried with below code and it working as expected.

    my $results = $csapi->QueryData($aUser, "Basic Summary", "has_patch_dev_child(type='problem') and (problem_number='3997')", undef, undef, undef);

    Thanks for your help Mike !!

     

    Regards

    Mahesh
     

     

  • Mike.Scharnow
    Mike.Scharnow
    70 Posts

    Re: Problem with Modify the CR Data using csapi

    ‏2013-11-13T17:04:28Z  

    Great, It is working.

    I have tried with below code and it working as expected.

    my $results = $csapi->QueryData($aUser, "Basic Summary", "has_patch_dev_child(type='problem') and (problem_number='3997')", undef, undef, undef);

    Thanks for your help Mike !!

     

    Regards

    Mahesh
     

     

    wait a moment.

    Is this really the query you used?

    Because this query will give you the CR 3997 if and only if it has children, it will not give you the children of 3997. -- I don't think that this is what you wanted.

    Try "has_patch_dev_child((type='problem' and (problem_number='3997'))"

  • mahesh12345
    mahesh12345
    8 Posts

    Re: Problem with Modify the CR Data using csapi

    ‏2013-11-13T18:30:06Z  

    wait a moment.

    Is this really the query you used?

    Because this query will give you the CR 3997 if and only if it has children, it will not give you the children of 3997. -- I don't think that this is what you wanted.

    Try "has_patch_dev_child((type='problem' and (problem_number='3997'))"

    Hi Mike,

     

         My requirement as follows:

           Script needs to retrive the child CR data (or) check if any child cr's are added/associated with parent cr.

    my $results = $csapi->QueryData($aUser, "Basic Summary", "has_patch_dev_child(type='problem') and (problem_number='3997')", undef, undef, undef);

    By using above code,i can get the data size as "1" for parent CR(3997) .

    Same if i tried with other parent CR which doesn't associated any child CR's,it is giving data size as "0".

    Hence above code fulfilled my requirement.

     

    Regards

    Mahesh

  • Mike.Scharnow
    Mike.Scharnow
    70 Posts

    Re: Problem with Modify the CR Data using csapi

    ‏2013-11-13T20:09:29Z  

    Hi Mike,

     

         My requirement as follows:

           Script needs to retrive the child CR data (or) check if any child cr's are added/associated with parent cr.

    my $results = $csapi->QueryData($aUser, "Basic Summary", "has_patch_dev_child(type='problem') and (problem_number='3997')", undef, undef, undef);

    By using above code,i can get the data size as "1" for parent CR(3997) .

    Same if i tried with other parent CR which doesn't associated any child CR's,it is giving data size as "0".

    Hence above code fulfilled my requirement.

     

    Regards

    Mahesh

    ok, if you only want to know if a CR has children, your query is correct. I thought that you wanted to collect which children a given CR has, if it has any.

    Sorry for the misunderstanding.

    Regards,
    Mike

  • R@mesh009
    R@mesh009
    17 Posts

    Re: Problem with Modify the CR Data using csapi

    ‏2015-04-28T05:47:40Z  

    Hi Mahesh,

    crstatus:

    Change does not allow you to manipulate the status directly (as in the GUI surface). You will need to make a transition from the current state to your destination state. Either you do this by using allowed transitions, or you must log in as an administrator, this would be the equivalent of  an "Admin Transition" in the gui.

    Check the csapi documentation regarding

    <pre style="color: rgb(0, 0, 0);">my $tmpstr = $csapi->TransitionCR($aUser, $tmp2); </pre>

    for examples.

     

    child information:

    First you need the name of the relation. In your case this should be "child" (corresponds to the attribute name that you defined in Change).

    Then you need the direction. It is either "has_<relation>" or "is_<relation>_of". This direction is used as a function for the query. So, to get the children of problem 12345, you would make a query like 

    <pre style="color: rgb(0, 0, 0);">my $tmp = $csapi->QueryData($aUser, "Basic Summary", "is_child_of(cr('12345')", undef, undef, undef); </pre>

    or equivalently

    <pre style="color: rgb(0, 0, 0);">my $tmp = $csapi->QueryData($aUser, "Basic Summary", "(is_child_of(problem_number='12345') and (cvtype='problem')", undef, undef, undef); </pre>

     

    hope this helps,

    BR,
    Mike

    I want to list down all the child CRs for the given CR number in Change Synergy. How can do the same.

  • Mike.Scharnow
    Mike.Scharnow
    70 Posts

    Re: Problem with Modify the CR Data using csapi

    ‏2015-04-28T06:19:15Z  
    • R@mesh009
    • ‏2015-04-28T05:47:40Z

    I want to list down all the child CRs for the given CR number in Change Synergy. How can do the same.

    same question, same answer.

    it depends on the name of the relationship. If it is called "child", see the answer from mahes12345 from Nov 13, 2013. If it is called differently, say "patch_child" see the posts from Nov 13

  • R@mesh009
    R@mesh009
    17 Posts

    Re: Problem with Modify the CR Data using csapi

    ‏2015-04-28T06:35:49Z  

    same question, same answer.

    it depends on the name of the relationship. If it is called "child", see the answer from mahes12345 from Nov 13, 2013. If it is called differently, say "patch_child" see the posts from Nov 13

    Yes Mike, my question is an extension to the same, where I want to list down all the child CR numbers for the given CR.

  • Mike.Scharnow
    Mike.Scharnow
    70 Posts

    Re: Problem with Modify the CR Data using csapi

    ‏2015-04-28T06:47:50Z  
    • R@mesh009
    • ‏2015-04-28T06:35:49Z

    Yes Mike, my question is an extension to the same, where I want to list down all the child CR numbers for the given CR.

    I understand, but why are you not satisfied with the given answer?

  • R@mesh009
    R@mesh009
    17 Posts

    Re: Problem with Modify the CR Data using csapi

    ‏2015-04-28T06:51:58Z  

    I understand, but why are you not satisfied with the given answer?

    The reason being it doesn't list me the CR numbers. I am expecting output like for the CR 3997, the child CRs are 3456 and 4564.

  • Mike.Scharnow
    Mike.Scharnow
    70 Posts

    Re: Problem with Modify the CR Data using csapi

    ‏2015-04-28T20:28:02Z  
    • R@mesh009
    • ‏2015-04-28T06:51:58Z

    The reason being it doesn't list me the CR numbers. I am expecting output like for the CR 3997, the child CRs are 3456 and 4564.

    Can you explain to me how and where you are working? are you writing a script? Perl? JavaScript? are you programming a report or using the change application? do you have a problem with the output or the query or with a specific environment/?

     

    Please provide some more information so that I can help you. Especially we will need the attribute name of your relation.

  • R@mesh009
    R@mesh009
    17 Posts

    Re: Problem with Modify the CR Data using csapi

    ‏2015-04-29T06:34:34Z  

    Can you explain to me how and where you are working? are you writing a script? Perl? JavaScript? are you programming a report or using the change application? do you have a problem with the output or the query or with a specific environment/?

     

    Please provide some more information so that I can help you. Especially we will need the attribute name of your relation.

    Hello Mike,

    I am using Perl. User enters versions: 1.0,1.1, for a particular CR in Change Synergy. My script would need to test, if there is any child CR pertaining to parent CR for the versions => 1.0 & 1.1 and create the one's which we do not have.

    Ex: 1234, CR has 2345(1.0) & 4567(1.1) as child CRs. I want to list down the CRs and their product version mapping then would decide to create or not.

     

  • Mike.Scharnow
    Mike.Scharnow
    70 Posts

    Re: Problem with Modify the CR Data using csapi

    ‏2015-04-29T08:15:41Z  
    • R@mesh009
    • ‏2015-04-29T06:34:34Z

    Hello Mike,

    I am using Perl. User enters versions: 1.0,1.1, for a particular CR in Change Synergy. My script would need to test, if there is any child CR pertaining to parent CR for the versions => 1.0 & 1.1 and create the one's which we do not have.

    Ex: 1234, CR has 2345(1.0) & 4567(1.1) as child CRs. I want to list down the CRs and their product version mapping then would decide to create or not.

     

    as said, you need to know which name the relation has. You can see this in the lifecycle definition.

    Let's assume the name is "child". In this case you have two directions, has_child and is_child_of.

    Let's assume the version attribute is called "delivery_version".

    So, you could write:

    my $problem_number = "1234";
    my $version_attribute = "delivery_version";
    my $queryString = "is_child_of(problem_number='$problem_number')";
    my $queryResults = $csapi->QueryData($aUser, "Basic Summary", "($queryString) and (cvtype='problem')", undef, undef, undef, "problem_number|$version_attribute");
    if( $queryResults->getDataSize() == 0 ) {
        # no children exist, create two crs
    } else {
        for ($childnum = 1 ; $childnum <= $queryResults->getDataSize() ; $childnum++) {
            my $current_version = $queryResults->getDataObject($childnum)->getDataObjectByName($version_attribute)->getValue();
            # there is one child with version $current_version
        }
        
    }
    

    did not check for typos but in general this should be what you need.

    hope this helps,
    Mike

    Edit: changed the query after re-reading the posts above...

    Updated on 2015-04-29T08:19:43Z at 2015-04-29T08:19:43Z by Mike.Scharnow
  • R@mesh009
    R@mesh009
    17 Posts

    Re: Problem with Modify the CR Data using csapi

    ‏2015-04-29T10:53:04Z  

    as said, you need to know which name the relation has. You can see this in the lifecycle definition.

    Let's assume the name is "child". In this case you have two directions, has_child and is_child_of.

    Let's assume the version attribute is called "delivery_version".

    So, you could write:

    <pre class="javascript dw" data-editor-lang="js" data-pbcklang="javascript" dir="ltr">my $problem_number = "1234"; my $version_attribute = "delivery_version"; my $queryString = "is_child_of(problem_number='$problem_number')"; my $queryResults = $csapi->QueryData($aUser, "Basic Summary", "($queryString) and (cvtype='problem')", undef, undef, undef, "problem_number|$version_attribute"); if( $queryResults->getDataSize() == 0 ) { # no children exist, create two crs } else { for ($childnum = 1 ; $childnum <= $queryResults->getDataSize() ; $childnum++) { my $current_version = $queryResults->getDataObject($childnum)->getDataObjectByName($version_attribute)->getValue(); # there is one child with version $current_version } } </pre>

    did not check for typos but in general this should be what you need.

    hope this helps,
    Mike

    Edit: changed the query after re-reading the posts above...

    Hello Mike,

    I have tried the following code and output is:

    my $problem_number = "$ARGV[0]";
    my $version_attribute = "product_version";
    my $queryString = "is_child_of(problem_number='$problem_number')";
    my $queryResults = $csapi->QueryData($aUser, "Basic Summary", "($queryString) and (cvtype='problem')", undef, undef, undef, "problem_number|$version_attribute");
    if( $queryResults->getDataSize() == 0 ) {
        # no children exist, create two crs
            print "getDataSize is : $queryResults->getDataSize()";
    } else {
        for ($childnum = 1 ; $childnum <= $queryResults->getDataSize() ; $childnum++) {
            my $current_version = $queryResults->getDataObject($childnum)->getDataObjectByName($version_attribute)->getValue();
            print "Current Version is: $current_version \n";
            # there is one child with version $current_version
        }
    }
     

    Output is:

    getDataSize is : ChangeSynergy::apiQueryData=HASH(0xbaae6a0)->getDataSize()