Topic
IC4NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
34 replies Latest Post - ‏2015-05-15T06:26:40Z by R@mesh009
jrhaighl3msuk
jrhaighl3msuk
3 Posts
ACCEPTED ANSWER

Pinned topic Creating a Change Request through CSAPI

‏2013-11-04T15:32:05Z |

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
    44 Posts
    ACCEPTED ANSWER

    Re: Creating a Change Request through CSAPI

    ‏2013-11-04T16:18:37Z  in response to jrhaighl3msuk

    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
      3 Posts
      ACCEPTED ANSWER

      Re: Creating a Change Request through CSAPI

      ‏2013-11-05T12:37:29Z  in response to Mike.Scharnow

      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
        ACCEPTED ANSWER

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

        ‏2013-11-08T13:17:43Z  in response to jrhaighl3msuk

        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
      ACCEPTED ANSWER

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

      ‏2013-11-09T06:32:54Z  in response to Mike.Scharnow

      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
        44 Posts
        ACCEPTED ANSWER

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

        ‏2013-11-09T08:22:53Z  in response to mahesh12345

        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
          ACCEPTED ANSWER

          Re: Problem with Modify the CR Data using csapi

          ‏2013-11-13T04:42:37Z  in response to Mike.Scharnow

          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
            44 Posts
            ACCEPTED ANSWER

            Re: Problem with Modify the CR Data using csapi

            ‏2013-11-13T09:55:21Z  in response to mahesh12345

            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
              ACCEPTED ANSWER

              Re: Problem with Modify the CR Data using csapi

              ‏2013-11-13T13:38:44Z  in response to Mike.Scharnow

              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
                44 Posts
                ACCEPTED ANSWER

                Re: Problem with Modify the CR Data using csapi

                ‏2013-11-13T14:03:30Z  in response to mahesh12345

                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
                  ACCEPTED ANSWER

                  Re: Problem with Modify the CR Data using csapi

                  ‏2013-11-13T15:32:24Z  in response to Mike.Scharnow

                  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
                    44 Posts
                    ACCEPTED ANSWER

                    Re: Problem with Modify the CR Data using csapi

                    ‏2013-11-13T15:41:56Z  in response to mahesh12345

                    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
                      ACCEPTED ANSWER

                      Re: Problem with Modify the CR Data using csapi

                      ‏2013-11-13T15:58:57Z  in response to Mike.Scharnow

                      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
                        44 Posts
                        ACCEPTED ANSWER

                        Re: Problem with Modify the CR Data using csapi

                        ‏2013-11-13T17:04:28Z  in response to mahesh12345

                        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
                          ACCEPTED ANSWER

                          Re: Problem with Modify the CR Data using csapi

                          ‏2013-11-13T18:30:06Z  in response to Mike.Scharnow

                          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
                            44 Posts
                            ACCEPTED ANSWER

                            Re: Problem with Modify the CR Data using csapi

                            ‏2013-11-13T20:09:29Z  in response to mahesh12345

                            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
              14 Posts
              ACCEPTED ANSWER

              Re: Problem with Modify the CR Data using csapi

              ‏2015-04-28T05:47:40Z  in response to Mike.Scharnow

              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
                44 Posts
                ACCEPTED ANSWER

                Re: Problem with Modify the CR Data using csapi

                ‏2015-04-28T06:19:15Z  in response to R@mesh009

                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
                  14 Posts
                  ACCEPTED ANSWER

                  Re: Problem with Modify the CR Data using csapi

                  ‏2015-04-28T06:35:49Z  in response to Mike.Scharnow

                  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
                    44 Posts
                    ACCEPTED ANSWER

                    Re: Problem with Modify the CR Data using csapi

                    ‏2015-04-28T06:47:50Z  in response to R@mesh009

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

                    • R@mesh009
                      R@mesh009
                      14 Posts
                      ACCEPTED ANSWER

                      Re: Problem with Modify the CR Data using csapi

                      ‏2015-04-28T06:51:58Z  in response to Mike.Scharnow

                      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
                        44 Posts
                        ACCEPTED ANSWER

                        Re: Problem with Modify the CR Data using csapi

                        ‏2015-04-28T20:28:02Z  in response to R@mesh009

                        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
                          14 Posts
                          ACCEPTED ANSWER

                          Re: Problem with Modify the CR Data using csapi

                          ‏2015-04-29T06:34:34Z  in response to Mike.Scharnow

                          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
                            44 Posts
                            ACCEPTED ANSWER

                            Re: Problem with Modify the CR Data using csapi

                            ‏2015-04-29T08:15:41Z  in response to R@mesh009

                            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
                              14 Posts
                              ACCEPTED ANSWER

                              Re: Problem with Modify the CR Data using csapi

                              ‏2015-04-29T10:53:04Z  in response to Mike.Scharnow

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

                              • Mike.Scharnow
                                Mike.Scharnow
                                44 Posts
                                ACCEPTED ANSWER

                                Re: Problem with Modify the CR Data using csapi

                                ‏2015-04-29T12:31:37Z  in response to R@mesh009

                                I recommend the site http://perlmaven.com/quoted-interpolated-and-escaped-strings-in-perl, it expains interpolation quite well.

                                For your script this means to change the lines:

                                my $problem_number = $ARGV[0];

                                and

                                print "getDataSize is : " . $queryResults->getDataSize();

                                • R@mesh009
                                  R@mesh009
                                  14 Posts
                                  ACCEPTED ANSWER

                                  Re: Problem with Modify the CR Data using csapi

                                  ‏2015-04-30T04:37:01Z  in response to Mike.Scharnow

                                  Hello Mike,

                                  It works both the ways.

                                  my $problem_number = "$ARGV[0]";
                                  print "Problem number is: $problem_number";
                                  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
                                      }
                                  }
                                   
                                  perl hasChildCRTest.pl 126
                                  Problem number is: 126getDataSize is : ChangeSynergy::apiQueryData=HASH(0x19c0e3e0)->getDataSize()

                                  Thanks and Regards,

                                  Kiran Kumar D.

                                  • Mike.Scharnow
                                    Mike.Scharnow
                                    44 Posts
                                    ACCEPTED ANSWER

                                    Re: Problem with Modify the CR Data using csapi

                                    ‏2015-04-30T06:36:36Z  in response to R@mesh009

                                    you are right that "$ARGV[0]" can indeed be evaluated correctly, sorry about that.

                                    print "getDataSize is : $queryResults->getDataSize()"; is definitively wrong as you see in the output...

                                    • R@mesh009
                                      R@mesh009
                                      14 Posts
                                      ACCEPTED ANSWER

                                      Re: Problem with Modify the CR Data using csapi

                                      ‏2015-04-30T06:53:38Z  in response to Mike.Scharnow

                                      yes Mike, sorry about that.

                                      Modified the code as follows:

                                      my $results = $csapi->QueryData($aUser, "Basic Summary", "has_patch_dev_child(type='problem') and (problem_number='$ARGV[0]')");
                                      print "Get Datasize is:" . $results->getDataSize() . "\n";
                                      #print "" . $results . "\n";

                                      my $tmp = $csapi->QueryData($aUser, "Basic Summary", "(is_child_of(problem_number='$ARGV[0]'))");
                                      print "Size is:" . $tmp->getDataSize() . "\n";
                                      #foreach $key(keys %$results)
                                      #{
                                      #       if($key =~ /objData/)
                                      #       {
                                      #               print "@{$results}{$key} \n";
                                      #       }
                                      #       else
                                      #       {
                                      #               print "$key and value is: ${$results}{$key}\n";
                                      #
                                      #       }
                                      #}
                                      #
                                      my $problem_number = '$ARGV[0]';
                                      print "Problem number is: $problem_number \n";
                                      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() . "\n";
                                      } 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
                                          }
                                      }
                                       

                                      The output now is:

                                      Get Datasize is:1
                                      Size is:0
                                      Problem number is: $ARGV[0]
                                      getDataSize is : 0

                                      So, the following are the open questions:

                                      1. How can I get the list of child CRs for a particular CR.

                                      2. Number of the CRs for a particular CR.


                                       

                                       

                                      • Mike.Scharnow
                                        Mike.Scharnow
                                        44 Posts
                                        ACCEPTED ANSWER

                                        Re: Problem with Modify the CR Data using csapi

                                        ‏2015-04-30T07:16:46Z  in response to R@mesh009

                                        these questions are more about "how to program perl" than "how to use change" and I don't want this thread to get too lengthy.

                                        - You still did not answer which name your relation attribute has. that's essential! From your first lines in your code, I would now say that the attribute name is "patch_dev_child", not "child". You need to clarify this! Otherwise your scripts will not work.

                                        - why did you replace the perfectly working
                                        my $problem_number = "$ARGV[0]";
                                        with the not working
                                        my $problem_number = '$ARGV[0]';
                                        ? And I still think it would be better to replace this with
                                        my $problem_number = $ARGV[0];
                                        as it is way easier to make clear what is done here: plainly take the parameter of the script and use it as the problem number to be evaluated
                                         

                                        About your question "1". What do you mean by "list"? If you want to get the problem numbers of the related CRs, change the line
                                        my $current_version = $queryResults->getDataObject($childnum)->getDataObjectByName($version_attribute)->getValue();
                                        to
                                        my $current_problem_number = $queryResults->getDataObject($childnum)->getDataObjectByName("problem_number)->getValue();
                                        (and of course change the print command in the next line)
                                         

                                         

                                        About your question "2": If in your second query you use the correct relation attribute name, then this code will give you the number of related CRs.
                                         

                                        • R@mesh009
                                          R@mesh009
                                          14 Posts
                                          ACCEPTED ANSWER

                                          Re: Problem with Modify the CR Data using csapi

                                          ‏2015-04-30T10:03:25Z  in response to Mike.Scharnow

                                          Hello Mike,

                                          To keep it simple:

                                          my $results = $csapi->QueryData($aUser, "Basic Summary", "has_patch_dev_child(type='problem') and (problem_number='126')");
                                          print "Get Datasize is:" . $results->getDataSize() . "\n";

                                          Gives the output as: 'Get Datasize is:1'

                                          The query I am trying to do is get the patch_dev_childs for the given CR.
                                          Though in this case, there are 2 CRs, it is just showing '1'.

                                          my $problem_number =126;
                                          print "Problem number is: $problem_number \n";
                                          my $version_attribute = "product_version";
                                          #my $queryString = "is_child_of(problem_number='$problem_number')";
                                          my $queryString = "has_patch_dev_child(type='problem') and (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() . "\n";
                                          } else {
                                              print "getDataSize is : ". $queryResults->getDataSize() . "\n";
                                              for ($childnum=1 ; $childnum <= $queryResults->getDataSize() ; $childnum++) {
                                              print "Inside for loop ... \n";
                                                  my $current_version = $queryResults->getDataObject($childnum)->getDataObjectByName($version_attribute)->getValue();
                                              print "Current Version is: $current_version \n";
                                              my $current_problem_number = $queryResults->getDataObject($childnum)->getDataObjectByName($problem_number)->getValue();
                                              print "Current Problem Number is: $current_problem_number \n";
                                                  # there is one child with version $current_version
                                                  }   
                                          }
                                          Get Datasize is:1
                                          Problem number is: 126
                                          getDataSize is : 1
                                          Inside for loop ...






                                           

                                          • Mike.Scharnow
                                            Mike.Scharnow
                                            44 Posts
                                            ACCEPTED ANSWER

                                            Re: Problem with Modify the CR Data using csapi

                                            ‏2015-04-30T11:28:09Z  in response to R@mesh009

                                            you must use the correct direction when looking at relations.

                                            Situation: 126 is parent, 137 and 148 are children. Relation is called "patch_dev_child"

                                            Then the following is true

                                            126 has_patch_dev_child 137

                                            126 has_patch_dev_child 148

                                            137 is_patch_dev_child_of 126

                                            148 is_patch_dev_child_of 126

                                            Now if you want to get the children of 126, you must make a query which says

                                            "give me the CRs that are patch-dev-children of all CRs for which the following condition is true:

                                            - the problem_number is 126"

                                            This would result in:

                                            ccm query "is_patch_dev_child_of( problem_number = '126' )"

                                             

                                            Let's try it this way.....
                                             

                                             

                                            • R@mesh009
                                              R@mesh009
                                              14 Posts
                                              ACCEPTED ANSWER

                                              Re: Problem with Modify the CR Data using csapi

                                              ‏2015-04-30T11:57:09Z  in response to Mike.Scharnow

                                              Perfect Mike.

                                              Just need one more step, want to know the CR 137,148 belongs to which product_version.

                                              My idea is to create a patch_dev_child for 126, if it doesn't exist for a product_version.

                                               

                                              • Mike.Scharnow
                                                Mike.Scharnow
                                                44 Posts
                                                ACCEPTED ANSWER

                                                Re: Problem with Modify the CR Data using csapi

                                                ‏2015-04-30T12:07:00Z  in response to R@mesh009

                                                this was already answered.

                                                my $version_attribute = "product_version";

                                                […]

                                                my $current_version = $queryResults->getDataObject($childnum)->getDataObjectByName($version_attribute)->getValue();

                                                • R@mesh009
                                                  R@mesh009
                                                  14 Posts
                                                  ACCEPTED ANSWER

                                                  Re: Problem with Modify the CR Data using csapi

                                                  ‏2015-05-15T06:26:40Z  in response to Mike.Scharnow

                                                  Thanks Mike, I am creating the child CR from the deduced result of the following function.

                                                  sub verifychildcr($problem_number,$prdversion)
                                                  {
                                                          my $csapi = new ChangeSynergy::csapi();
                                                          $csapi->setUpConnection("<Change Synergy URL>");
                                                          my $aUser = $csapi->Login("user", "user", "User", "database");

                                                          my ($problem_number,$prdversion)=@_;
                                                          chomp($problem_number);
                                                          chomp($prdversion);
                                                          my $version_attribute = "product_version";
                                                          my $queryString = "is_patch_dev_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 crs
                                                                  $log->info("getDataSize is : ". $queryResults->getDataSize() . "\n");
                                                                  return false;
                                                          }
                                                           else
                                                          {
                                                                  for ($childnum=0; $childnum < $queryResults->getDataSize(); $childnum++)
                                                                  {
                                                                          my $current_version = $queryResults->getDataObject($childnum)->getDataObjectByName($version_attribute)->getValue();
                                                                          my $childcr= $queryResults->getDataObject($childnum)->getDataObjectByName('problem_number')->getValue();
                                                                          if($current_version == $prdversion)
                                                                          {
                                                                                  return true;
                                                                          }
                                                                  }
                                                          }
                                                  }