1

I am trying to fetch the approval comments from ProcessInstanceStep object to a custom field named "Commnets" of another object named Order. I have written the below code. but somehow unable to fetch the comments. could anyone pls suggest. Thanks in advance!!

 public class ApprProcess {
    public static void ProcessInst(Order [] o1) {
        for(Order o2:o1) {
            ProcessInstance [] op = [SELECT Id,Status,(SELECT Id,Comments 
                                                       FROM Order)
                                     FROM ProcessInstance limit 1];
            for (ProcessInstance op1 : op) {
                for (ProcessInstanceStep pis : op1.Steps) {
                    if(op1.Status == 'Approved') {
                        o2.Approved_Comments__c = pis.Comments;
                    }
                }
            }
        }  
    } 
}

2 Answers 2

1

You should query from Step instead of order in your subquery.

2
  • I changed the query to "SELECT Id,Status,(SELECT Id, StepStatus, Comments FROM ProcessInstanceStep)FROM ProcessInstance limit 1" . However , getting an error - Didn't understand relationship 'ProcessInstanceStep' in FROM part of query call
    – user4644
    Commented Apr 8, 2014 at 8:54
  • change it to steps as per this reference, salesforce.com/us/developer/docs/api/Content/…
    – anmrk
    Commented Apr 8, 2014 at 9:08
0

try this ::

var commentsQry = "SELECT Comments FROM ProcessInstanceStep where     ProcessInstanceId = '"+processInstanceId+"'" ;
             var excutecommentsQry= sforce.connection.query(commentsQry);
             var commentsQryRecord = excutecommentsQry.getArray("records");
             var comm="";

             for(var i=0; i < commentsQryRecord.length ; i ++)
             {
                 if(commentsQryRecord[i].Comments != null)
                 {
                   alert(commentsQryRecord[i].Comments);
                   comm=comm+commentsQryRecord[i].Comments;
                 }
             }
            var  element_Comments = document.getElementById("comments");
            element_Comments.value=comm;
2
  • Sorry didn't know how to post. Please use the whole code. Commented Mar 18, 2015 at 16:09
  • Maybe you add some useful description? Commented Mar 18, 2015 at 16:10

You must log in to answer this question.