how can I prepopulate the fields of current task with previous completed task details

Certified Associate Developer

how can I prepopulate the fields of current task with previous completed task details?

  Discussion posts and replies are publicly visible

Parents
  • Hi ,

    To accomplish that, you have to pass the variable as reference between both tasks (within the process). Then, In Form 2 (Task Nº 2), use the ri! variables to set the values of the fields you want to populate.

    Dont forget to use activity classes and process variables correctly in order to obtain the desired result. Here is an example:


    Task 1 Interface





    Task 2 Interface



    Process



    Process Task 1 Detail







    Process Task 2 Detail



    Hope it helps,

    Rómulo

  • 0
    Certified Associate Developer
    in reply to Rómulo

    Thank you for the reply  , need some clarification that with the above one can I populate the details in the same form 

  • 0
    Certified Associate Developer
    in reply to Sanchit Gupta (Xebia)

    Hi Sanchit,

    I am trying to auto populate some details in the field reviewer, By following the below code I am able to populate the data from the previous task .

    But my question is if I didnt made any changes in the prepopulated data it was not saved into the db.How can I savethe prepopulated data as it is into DB?

    Many thanks in advance

     local!BCreviewer:rule!ISR_toget_BC_Reviewer(ISR_Studyrequest: ri!studyRequest.studyRequestId),
     
     value: if(rule!APN_isBlank(local!BCreviewer),ri!studyMedicalReview.BCReviewedBy,local!BCreviewer)
     saveInto: if(rule!APN_isBlank(local!BCreviewer),ri!studyMedicalReview.BCReviewedBy,(local!BCreviewer,ri!studyMedicalReview.BCReviewedBy)),

  • +1
    Certified Lead Developer
    in reply to sireesha

    You will need to make sure the value you want ends up being populated into your Rule Input CDT.

    If you know the value in advance and can evaluate the expression that originally populates it, earlier (as in prior to the form being reached), one method is to pre-populate the CDT before the first task is reached.

    However if you're just referring to a value pre-populated on the second task, then I'm unclear why the value isn't already stored in your PV CDT that you're passing into the second form.  If it is, then you shouldn't necessarily need to re-initialize it on that form and shouldn't need to mess with the local variable at all.

    Finally, one of the simplest and most standard ways to store the value captured in the local variable into the rule input CDT field, upon form submission (regardless of the answer to the above question), is to use an a!save() statement in the saveInto of the Submit button, and copy the local variable's value into the correct field.  I try to reserve this method for when it's truly necessary and won't add unnecessary complexity.

    It's hard to judge here without being able to take your full code into context... but I'd suggest revising a few things here...

    a!localVariables(
      
      /* instead of multiple messy if(isNull()) statements, simply do that check here, then only use this local variable until Submit time */
      local!BCreviewer: a!defaultValue(
        value: ri!studyMedicalReview.BCReviewedBy,
        default: rule!ISR_toget_BC_Reviewer(ISR_Studyrequest: ri!studyRequest.studyRequestId)
      ),
    
      (...)
      
        value: local!BCReviewer,
        saveInto: local!BCReviewer,
      
      (...)
      
      primaryButtons: {
        a!buttonWidget(
          label: "Submit",
          submit: true(),
          
          saveInto: {
            ri!buttonPressed,
            
            a!save(
              ri!studyMedicalReview.BCReviewedBy,
              local!BCReviewer
            )
          }
        )
      }
    )

  • 0
    Certified Associate Developer
    in reply to Mike Schmitt

    Thank you so much for the reply Mike.

    I wanted to prepopulate some data to BCrevierwer for example  ABC  is the BC reviwer already stored in the table StudyMedicalReviewer to reference studyrequest ID.

    If we get the task for same studyRequest Id I need to have ABC as the BCreviwer for the requestId.If we want to change that name we can change too--this is the requirement

    a!localvariable{
    local!BCreviewer:rule!ISR_toget_BC_Reviewer(ISR_Studyrequest: ri!studyRequest.studyRequestId),
    //rule to get the BC reviwer from the table with reference studyrequest Id//
    
     a!sideBySideLayout(
              items: {
                a!sideBySideItem(
                  item: a!textField(
                    label: "Business Conduct Reviewer",
                    labelPosition: "ABOVE",
                    value: if(rule!APN_isBlank(local!BCreviewer),ri!studyMedicalReview.BCReviewedBy,local!BCreviewer),
                    saveInto: if(rule!APN_isBlank(local!BCreviewer),ri!studyMedicalReview.BCReviewedBy,(local!BCreviewer,ri!studyMedicalReview.BCReviewedBy)),
                    showWhen: if(
                      local!businessCounduct,
                      true(),
                      false()
                    ),
                    required: if(
                      ri!studyMedicalReview.decision = cons!ISR_TEXT_DECISION_MEDREVDEC_FRINFO_CODE,
                      false(),
                      true()
                    )
                  )
                ),
                a!sideBySideItem(
                  item: a!dateField(
                    label: "Business Conduct Reviewed On",
                    labelPosition: "ABOVE",
                    value: if(rule!APN_isBlank(local!BCrevieweddate),ri!studyMedicalReview.BCReviewedOn,local!BCrevieweddate),
                    //If the rule value is not there I mean if there is no reviewer for that studyRequestID then value goes to table// 
                    saveInto: if(rule!APN_isBlank(local!BCrevieweddate),{ri!studyMedicalReview.BCReviewedOn},{local!BCrevieweddate,ri!studyMedicalReview.BCReviewedOn}),
                
                    
                   
                  )
                )
              }
            ),

    I have write the above code. for example ABC is BC reviewer for study RequestId=2 then ,in the form BC reviewer is populated as ABC. if we keep that ABC without editing then it wont saved into the DB again with the same StudyRequestID.If I made it to ABCD then it will saved into DB.

    So how can I save the prepopulated data without editing into the table again with same studyrequest id=2

    Could please help me?

    Many thanks in advance

  • 0
    Certified Lead Developer
    in reply to sireesha
    So how can I save the prepopulated data without editing into the table again with same studyrequest id=2

    The code snippet I provided in my earlier reply above should demonstrate how to do this for basically any value field.  I'm unclear why you need to revert my suggested changes, as it doesn't seem to add anything that isn't still accomplished in my version (the "reviewed on" field seems to rely on totally unrelated data, no?)

  • 0
    Certified Associate Developer
    in reply to Mike Schmitt

    Thank you so much Mike it was helpful.

  • +1
    Certified Lead Developer
    in reply to sireesha

    This version would be what I'd suggest as a starting point for handling both value fields in a similar manner, BTW.

    Also thanks for confirming - as always I'd request clicking verify on any/all answer(s) of mine you found directly helpful, lol.

    a!localVariables(
    
      /* instead of multiple messy if(isNull()) statements, simply do that check here, then only use this local variable until Submit time */
      local!BCreviewer: a!defaultValue(
        value: ri!studyMedicalReview.BCReviewedBy,
        default: rule!ISR_toget_BC_Reviewer(ISR_Studyrequest: ri!studyRequest.studyRequestId)
      ),
      local!BCReviewedOn: a!defaultValue(
        value: ri!studyMedicalReview.BCReviewedOn,
        default: null()
      ),
    
      (...)
    
      a!sideBySideLayout(
        items: {
          a!sideBySideItem(
            item: a!textField(
              label: "Business Conduct Reviewer",
              labelPosition: "ABOVE",
              value: local!BCreviewer,
              saveInto: local!BCreviewer,
              showWhen: if(
                local!businessCounduct,
                true(),
                false()
              ),
              required: if(
                ri!studyMedicalReview.decision = cons!ISR_TEXT_DECISION_MEDREVDEC_FRINFO_CODE,
                false(),
                true()
              )
            )
          ),
          a!sideBySideItem(
            item: a!dateField(
              label: "Business Conduct Reviewed On",
              labelPosition: "ABOVE",
              value: local!BCrevieweddate,
              /* If the rule value is not there I mean if there is no reviewer for that studyRequestID then value goes to table */
              saveInto: local!BCrevieweddate,
    
            )
          )
        }
      ),
    
      (...)
    
      primaryButtons: {
        a!buttonWidget(
          label: "Submit",
          submit: true(),
    
          saveInto: {
            ri!buttonPressed,
    
            a!save(
              ri!studyMedicalReview.BCReviewedBy,
              local!BCReviewer
            ),
            a!save(
              ri!studyMedicalReview.BCReviewedOn,
              local!BCReviewedOn
            )
          }
          
        )
      }
    )

  • 0
    Certified Associate Developer
    in reply to Mike Schmitt

    a!localvariables(
    
    local!internalComment: if(
    rule!APN_isBlank(index(ri!internalComment, "comment", {})),
    {},
    index(ri!internalComment, "comment", {})
    ),
    
    local!repeatedinternalcomment:a!defaultValue(value:local!internalComment,
    default: rule!ISR_get_internalcomment_for_repeatedfinalchecks(ISR_Studyrequest: ri!studyRequest.studyRequestId)),
    
    a!sideBySideItem(
    item: a!paragraphField(
    label: "Internal Review Comments",
    labelPosition: "ABOVE",
    value:local!repeatedinternalcomment,
    saveInto:
    {local!internalComment,
    a!save(
    ri!internalComment,
    'type!{urn:com:appian:types:ISR}ISR_StudyComment'(
    commentId: if(
    rule!APN_isBlank(ri!internalComment.commentId),
    {},
    ri!internalComment.commentId
    ),
    comment: local!internalcomment,
    isInternal: true(),
    reviewStage: cons!ISR_TEXT_REVIEWSTAGE_CODE_MEDIREV,
    isActive: true(),
    createdBy: loggedInUser(),
    createdOn: now(),
    updatedBy: loggedInUser(),
    updatedOn: now()
    )
    )}
    {local!repeatedinternalcomment,
    a!save(
    ri!internalComment,
    'type!{urn:com:appian:types:ISR}ISR_StudyComment'(
    commentId: if(
    rule!APN_isBlank(ri!internalComment.commentId),
    {},
    ri!internalComment.commentId
    ),
    comment: local!repeatedinternalcomment,
    isInternal: true(),
    reviewStage: cons!ISR_TEXT_REVIEWSTAGE_CODE_MEDIREV,
    isActive: true(),
    createdBy: loggedInUser(),
    createdOn: now(),
    updatedBy: loggedInUser(),
    updatedOn: now()
    )
    )},
    refreshAfter:"UNFOCUS",
    height: "MEDIUM",
    validations: if(
    len(ri!internalComment.comment) > cons!ISR_PARAGRAPH_LENGTH,
    "Comment must be " & cons!ISR_PARAGRAPH_LENGTH & " characters or fewer",
    {}
    )
    )
    How can I use a!save function for above code at the submit button to save the local variable values?

  • 0
    Certified Lead Developer
    in reply to sireesha
    How can I use a!save function for above code at the submit button

    I can't really judge by the code you've posted here as you didn't include your button or any hint of what you're currently trying.  My example directly above contains a button with two a!save() commands - did you find this to not work? Are you having a particular issue?  As-is, I can't really even guess as to any particular suggestions.

    Also: thanks for using a Code Box, but I'd advise/request you to also make sure you copy your code directly out of the expression/interface editor before pasting, in order to preserve indentation -- because without any indentation, it stays pretty difficult to read in its current form.

  • 0
    Certified Associate Developer
    in reply to Mike Schmitt

    a!localVariables(
    local!internalcomment: if(
        rule!APN_isBlank(index(ri!internalcomment, "comment", {})),
        {},
        index(ri!internalcomment, "comment", {})
      ),
      
       
      local!BCreviewer: a!defaultValue(
        value: local!internalcomment,
        default: rule!repeatedcomm(ISR_Studyrequest: ri!studyRequest.studyRequestId)
      ),
    
      (...)
      
        value: local!repeatedinternalcomment,
        saveInto:{local!internalcomment,
                      a!save(
                        ri!internalcomment,
                        'type!{urn:com:appian:types:ISR}ISR_Studycomment'(
                          commentId: if(
                            rule!APN_isBlank(ri!internalComment.commentId),
                            {},
                            ri!internalcomment.commentId
                          ),
                          comment: local!internalcomment,
                          isInternal: true(),
                          reviewStage: cons!ISR_TEXT_REVIEWSTAGE_CODE_MEDIREV,
                          isActive: true(),
                          createdBy: loggedInUser(),
                          createdOn: now(),
                          updatedBy: loggedInUser(),
                          updatedOn: now()
                        )
                      )}
                      {local!repeatedinternalcomment,
                      a!save(
                        ri!internalcomment,
                        'type!{urn:com:appian:types:ISR}ISR_StudyComment'(
                          commentId: if(
                            rule!APN_isBlank(ri!internalcomment.commentId),
                            {},
                            ri!internalComment.commentId
                          ),
                          comment: local!repeatedinternalcomment,
                          isInternal: true(),
                          reviewStage: cons!ISR_TEXT_REVIEWSTAGE_CODE_MEDIREV,
                          isActive: true(),
                          createdBy: loggedInUser(),
                          createdOn: now(),
                          updatedBy: loggedInUser(),
                          updatedOn: now()
                        )
                      )},
      
      (...)
      
      primaryButtons: {
        a!buttonWidget(
          label: "Submit",
          submit: true(),
          
          saveInto: {
            ri!buttonPressed,
            
            a!save(
              {ri!internalcomment,
              local!intrenalcomment},
              local!repeatedinternalcomment
            )
          }
        )
      }
    )

    Thank you for the all the helps Mike.

    I am trying the above code but it showing the error like this.If I use the code without using the a!save function at Submit button it was working fine but when I am trying to save that by using the a!save I am getting the error like this 

  • 0
    Certified Lead Developer
    in reply to sireesha

    from what I can tell, "local!repeatedInternalComment" is text, and much like what the error message you showed here suggests, you're trying to save that into the target of ri!internalComment, which is a CDT.

    As a refresher, when you call a!save, the first parameter (whether a single item or a list of items) is the TARGET of the save operation, and the second parameter is the VALUE.

    If your TARGET is or includes a CDT, that implies that you're trying to overwrite that entire cdt value with the item in the VALUE parameter, which in this case is just text.  This is *exactly* what your error message is telling you:

    You should probably simplify your a!save statement, remove the (misspelled) local!intrenalComment target, and save directly into the comment property of ri!internalComment.

    a!save(
      ri!internalcomment.comment,
      local!repeatedinternalcomment
    )

    Additionally: i'm unclear why you're even trying to do this save on the Button Click here, because from what I can tell from your code, you're manually modifying the value of ri!internalComment every time the text value is updated as well.  This is OK, but it also means that you don't really need to worry about doing the saveInto in the button - that technique is really reserved for when you want to copy local values (that is, things being stored ONLY in local values) into a Rule Input, upon Form Submission (and not until then).  There's not much point in doing both.

Reply
  • 0
    Certified Lead Developer
    in reply to sireesha

    from what I can tell, "local!repeatedInternalComment" is text, and much like what the error message you showed here suggests, you're trying to save that into the target of ri!internalComment, which is a CDT.

    As a refresher, when you call a!save, the first parameter (whether a single item or a list of items) is the TARGET of the save operation, and the second parameter is the VALUE.

    If your TARGET is or includes a CDT, that implies that you're trying to overwrite that entire cdt value with the item in the VALUE parameter, which in this case is just text.  This is *exactly* what your error message is telling you:

    You should probably simplify your a!save statement, remove the (misspelled) local!intrenalComment target, and save directly into the comment property of ri!internalComment.

    a!save(
      ri!internalcomment.comment,
      local!repeatedinternalcomment
    )

    Additionally: i'm unclear why you're even trying to do this save on the Button Click here, because from what I can tell from your code, you're manually modifying the value of ri!internalComment every time the text value is updated as well.  This is OK, but it also means that you don't really need to worry about doing the saveInto in the button - that technique is really reserved for when you want to copy local values (that is, things being stored ONLY in local values) into a Rule Input, upon Form Submission (and not until then).  There's not much point in doing both.

Children
No Data