how to edit groups in group picker which are stored in database as groupids with a related action from a form

how to edit groups in group picker which are stored in database as groupids with a related action from a form

  Discussion posts and replies are publicly visible

  • 0
    Certified Lead Developer

    What have you already tried and/or what errors are you getting?  Can you provide any further context?

  • a!localVariables(
      local!groups:a!forEach(
        ri!attendees,
        togroup(fv!item.groupid)
      ),
      
     a!formLayout(
    label:"Update Meeting Information",
    contents: {
    a!columnsLayout(
    columns: {
    a!columnLayout(
    contents: {
    a!textField(
      label: "Meeting Subject ",
      labelPosition:"ABOVE",
      value: ri!MMS_Meetinginfo.subject,
      saveInto: ri!MMS_Meetinginfo.subject,
      required: true,
      validations: if(
        len(
          ri!MMS_Meetinginfo.subject
        ) > 50,
        "Value may not be longer than 50 characters. You have entered " & len(
          ri!MMS_Meetinginfo.subject
        ) & " characters.",
        null
      )
    ),
    
    
    a!paragraphField(
      label: "Meeting Body",
      labelPosition: "ABOVE",
      value: ri!MMS_Meetinginfo.body,
      saveInto: ri!MMS_Meetinginfo.body,
      refreshAfter: "UNFOCUS",
      height: "MEDIUM",
      required: true
    ),
    
    
    a!textField(
      label: "Location",
      labelPosition: "ABOVE",
      value: ri!MMS_Meetinginfo.location,
      saveInto: ri!MMS_Meetinginfo.location,
      required: true,
      validations: if(
        len(
          ri!MMS_Meetinginfo.location
        ) > 50,
        "Value may not be longer than 50 characters. You have entered " & len(
          ri!MMS_Meetinginfo.location
        ) & " characters.",
        null
      )
    )
    
    }
    ),
    a!columnLayout(
    contents: {
    
    
    a!pickerFieldGroups(
      label: "Attendees",
      labelPosition: "ABOVE",
      maxSelections: 2,
      value:local!groups,
      saveInto:{
        a!save(local!groups,union(save!value,save!value)),
        
      },
      required: true
    
    ),
    a!dateTimeField(
      label: "Start Time",
      labelPosition:"ABOVE",
      value: ri!MMS_Meetinginfo.startTime,
      saveInto: ri!MMS_Meetinginfo.startTime,
      required: true,
      validations: if(ri!MMS_Meetinginfo.startTime>now(),null,"start date time must not be past date time  ")
    ),
    
    
    
    a!dateTimeField(
      label: "End Time",
      labelPosition:"ABOVE",
      value: ri!MMS_Meetinginfo.endTime,
      saveInto: ri!MMS_Meetinginfo.endTime,
      required: true,
      validations:if(ri!MMS_Meetinginfo.endTime>ri!MMS_Meetinginfo.startTime,null,"end date time must not be less than start date time  ")
    )
    
    
        }
      )
          },
    showWhen: ri!MMS_Meetinginfo.startTime-time(0,10,0,0)>gmt(now(),"IST")
     ),
    a!cardLayout(
          contents: {
            a!richTextDisplayField(
              value:a!richTextItem(
                text:"Meeting that you want to update is either ongoing or been completed",
                size: "MEDIUM_PLUS",
                color:"ACCENT",
                style: "EMPHASIS"
              ),
              align:"CENTER"
            )
          },
          height: "AUTO",
          style: "INFO",
          marginBelow: "STANDARD",
          showWhen: not(ri!MMS_Meetinginfo.startTime-time(0,10,0,0)>gmt(now(),"IST"))
        )
      },
      buttons:{
      a!buttonLayout(
        primaryButtons: {
          a!buttonWidget(
            label: "UPDATE MEETING",
            icon: "envelope",
            saveInto: {
              a!foreach(local!groups,a!save(ri!attendees,append(ri!attendees,{groupid:tointeger(fv!item)}))),
              a!save(ri!MMS_Meetinginfo.startTime,gmt(ri!MMS_Meetinginfo.startTime,"IST")),
              a!save(ri!MMS_Meetinginfo.endTime,gmt(ri!MMS_Meetinginfo.endTime,"IST")),
              a!save(ri!MMS_Meetinginfo.createdBy,loggedInUser()),
              a!save(ri!readOnly,true)
             
            },
            submit: true,
            style: "PRIMARY",
            showWhen: ri!MMS_Meetinginfo.startTime-time(0,10,0,0)>gmt(now(),"IST")
          )
        },
        showWhen: ri!MMS_Meetinginfo.startTime-time(0,10,0,0)>gmt(now(),"IST")
        
       
      )
     
      }
      
      
    )
    
    )
    i have a requirement like i need to send a meeting form that is been assigned to a set of groups and there should be a related action that can add or delete groups within that meeting form

    for  selecting groups i have used a group picker and stored that selected values as ids within a cdt attendees with meeting id as primary key and i have got this groupids using this meetingid and stored into a

     local variable by converting that groupids to groups in related action form but i when i remove a group that is already existing it is geeting removed here in the form but it is showing within the record 

    can anyone explain how can i solve this problem

    this is the code related to related action from and ri!attendees store groupisds related to a meetingid and ri!meetinginfo stored meetinginfo

    it is a start form with process model that is writing the updated data i.e group data to db

  • 0
    Certified Lead Developer
    in reply to vinayvarma

    Hi,

    I'll take a look through your code when I have a chance.  In the mean time, I'd like to request you edit your comment and, instead of pasting all the code directly into the comment text, use the "Insert Code" feature found here in the "Insert" menu, and paste it all in a code box (make sure to grab an original copy that still has original indentation etc).  This preserves both indentation as well as preventing a thread from becoming unreadable due to the way long code can blow out a single comment like the above.

    Thanks! Smiley

  • This part looks like the issue to me in your group picker:

    saveInto:{
      union(local!groups,local!groups),
      a!foreach(local!groups,append(local!groups,{groupid:fv!item.groupid}))
    },

    Your saveInto should receive either a variable to save into or a!save() to explicitly define a target variable and value. In your case, I think you need to save the results of this picker into a rule input so that the datase will be updated once you change the groups.

    I'm not exactly sure how you're using the rule inpt (so it may not be this easy), but the first thing I'd try is to just define your save as local!groups. Then you could have your submit button transfer the items from local!groups back to your rule input rather than trying to do it all within this component.

  • a!localVariables(
      local!groups:a!forEach(
        ri!attendees,
        togroup(fv!item.groupid)
      ),
      
     a!formLayout(
    label:"Update Meeting Information",
    contents: {
    a!columnsLayout(
    columns: {
    a!columnLayout(
    contents: {
    a!textField(
      label: "Meeting Subject ",
      labelPosition:"ABOVE",
      value: ri!MMS_Meetinginfo.subject,
      saveInto: ri!MMS_Meetinginfo.subject,
      required: true,
      validations: if(
        len(
          ri!MMS_Meetinginfo.subject
        ) > 50,
        "Value may not be longer than 50 characters. You have entered " & len(
          ri!MMS_Meetinginfo.subject
        ) & " characters.",
        null
      )
    ),
    
    
    a!paragraphField(
      label: "Meeting Body",
      labelPosition: "ABOVE",
      value: ri!MMS_Meetinginfo.body,
      saveInto: ri!MMS_Meetinginfo.body,
      refreshAfter: "UNFOCUS",
      height: "MEDIUM",
      required: true
    ),
    
    
    a!textField(
      label: "Location",
      labelPosition: "ABOVE",
      value: ri!MMS_Meetinginfo.location,
      saveInto: ri!MMS_Meetinginfo.location,
      required: true,
      validations: if(
        len(
          ri!MMS_Meetinginfo.location
        ) > 50,
        "Value may not be longer than 50 characters. You have entered " & len(
          ri!MMS_Meetinginfo.location
        ) & " characters.",
        null
      )
    )
    
    }
    ),
    a!columnLayout(
    contents: {
    
    
    a!pickerFieldGroups(
      label: "Attendees",
      labelPosition: "ABOVE",
      maxSelections: 2,
      value:local!groups,
      saveInto:{
        a!save(local!groups,union(save!value,save!value)),
        
      },
      required: true
    
    ),
    a!dateTimeField(
      label: "Start Time",
      labelPosition:"ABOVE",
      value: ri!MMS_Meetinginfo.startTime,
      saveInto: ri!MMS_Meetinginfo.startTime,
      required: true,
      validations: if(ri!MMS_Meetinginfo.startTime>now(),null,"start date time must not be past date time  ")
    ),
    
    
    
    a!dateTimeField(
      label: "End Time",
      labelPosition:"ABOVE",
      value: ri!MMS_Meetinginfo.endTime,
      saveInto: ri!MMS_Meetinginfo.endTime,
      required: true,
      validations:if(ri!MMS_Meetinginfo.endTime>ri!MMS_Meetinginfo.startTime,null,"end date time must not be less than start date time  ")
    )
    
    
        }
      )
          },
    showWhen: ri!MMS_Meetinginfo.startTime-time(0,10,0,0)>gmt(now(),"IST")
     ),
    a!cardLayout(
          contents: {
            a!richTextDisplayField(
              value:a!richTextItem(
                text:"Meeting that you want to update is either ongoing or been completed",
                size: "MEDIUM_PLUS",
                color:"ACCENT",
                style: "EMPHASIS"
              ),
              align:"CENTER"
            )
          },
          height: "AUTO",
          style: "INFO",
          marginBelow: "STANDARD",
          showWhen: not(ri!MMS_Meetinginfo.startTime-time(0,10,0,0)>gmt(now(),"IST"))
        )
      },
      buttons:{
      a!buttonLayout(
        primaryButtons: {
          a!buttonWidget(
            label: "UPDATE MEETING",
            icon: "envelope",
            saveInto: {
              a!foreach(local!groups,a!save(ri!attendees,append(ri!attendees,{groupid:tointeger(fv!item)}))),
              a!save(ri!MMS_Meetinginfo.startTime,gmt(ri!MMS_Meetinginfo.startTime,"IST")),
              a!save(ri!MMS_Meetinginfo.endTime,gmt(ri!MMS_Meetinginfo.endTime,"IST")),
              a!save(ri!MMS_Meetinginfo.createdBy,loggedInUser()),
              a!save(ri!readOnly,true)
             
            },
            submit: true,
            style: "PRIMARY",
            showWhen: ri!MMS_Meetinginfo.startTime-time(0,10,0,0)>gmt(now(),"IST")
          )
        },
        showWhen: ri!MMS_Meetinginfo.startTime-time(0,10,0,0)>gmt(now(),"IST")
        
       
      )
     
      }
      
      
    )
    
    )

  • can u please look at my code i have edited it and placed 

    a!foreach(local!groups,a!save(ri!attendees,append(ri!attendees,{groupid:tointeger(fv!item)}))) in saveinto parameter of update button but even thought i am getting duplicate and more groups after clicking update button

  • 0
    Certified Lead Developer
    in reply to vinayvarma

    The way you have the a!save() inside an a!forEach() loop, I'm not surprised it's creating a repeating list of results inside your ri!attendees variable.  I think you might have more luck structuring it like this instead:

    a!save(
      ri!attendees,
      rule!APN_Distinct(
        a!forEach(
          local!groups,
          {
            groupId: tointeger(fv!item)
          }
        )
      )
    )

    You should set up a utility rule in your system i.e. 'APN_Distinct()' which handles the "union(ri!array, ri!array)" functionality.  This will allow you to skip using the ugly (and sometimes inefficient) manual use of the union() function in hardcode -- for instance, in my code snippet above, you would've had to run the a!forEach() loop twice to do a self-union, but instead we can just pass it straight into the utility rule and the rule handles it.