I want to generate a form dynamicaly in a workflow ? How can we achive that

Which IIQ version are you inquiring about?

Version 8.2

Share all details related to your problem, including any error messages you may have received.

There is a quicklink that triggers a workflow. Within a workflow a form needs to be generated that may contain n number of fields (Depending on situation). How can we achieve that ? Below is the code snipped I am using in a workflow rule to generate a form. The form doesn’t load. There is no error in logs.

import sailpoint.object.*;
  import sailpoint.api.*;
  import java.util.*;
  import sailpoint.object.Workflow.Step;
  import sailpoint.object.Form.Section;
  import sailpoint.object.Form.Button;
  
  Workflow.Approval wa= new Workflow.Approval();
  Workflow.Step ws= new Workflow.Step();
  Button btn= new Button();
  Form forms = new Form();
  forms.setName("Hello Form");
  forms.setLabelAlign("Form Label");
  System.out.println("-------------------------");
  Section sects = new Section();
  sects.setName("Section name");
  sects.setType("text");
  sects.setLabel("Sec Label");
  Field fv = new Field();
  fv.setName("fieldname");
  fv.setType("String");
  fv.setValue(workflow.get("launcher"));

  sects.add(fv);
  forms.add(sects);
  forms.setPageTitle("Form Page Title");
  forms.add(fv);
  btn.setAction("next");
  btn.setLabel("Ok");
  List bList = new ArrayList();
  bList.add(btn);
  forms.setButtons(bList);
 // context.saveObject(forms);
 // context.commitTransaction();
  Identity idn = context.getObjectByName(Identity.class,"spadmin");
  System.out.println("idn : "+idn);
  System.out.println("forms : "+forms.toXml());
  wa.setName("workflow approval");
  wa.setForm(forms);
  wa.setOwner(workflow.get("launcher").toString());
  wa.setReturn("");
  wa.setSend("");
  wa.setAssimilated(true);


  //
  System.out.println("wa : "+wa.toXml());
  System.out.println("ws : "+ws.toXml());
  return wa;

Hi Tanay,
First of all I would suggest to not create form from scratch as it might be tricky. Apart from that what you can do is to just create a standard step with the Form and in this form just create a single field which is hidden.

In this field you can write beanshell that will customize the form object. That gives you benefit that form itself is created by Sailpoint and the only thing you do is to dynamically build it inside.

Here see some examples:

  1. Form example
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE Form PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<Form name="Sample Workflow Form" type="Workflow">
  <Attributes>
    <Map>
      <entry key="pageTitle" value="Sample Workflow Form"/>
      <entry key="subtitle" value="Sample Workflow Form"/>
      <entry key="title" value="Sample Workflow Form"/>
    </Map>
  </Attributes>
  <Description></Description>
  <Section name="Section 1">
    <Field name="configField" type="string">
      <Attributes>
        <Map>
          <entry key="hidden" value="true"/>
        </Map>
      </Attributes>
      <Script>
        <Source>
          <![CDATA[
          for(Form.Section baseSection : form.getSections()) {
               baseSection.load();
               Field field = new Field();
               field.setName("someFieldName");
               field.setType("string");
               
               baseSection.add(field); 

               form.load();
        }
	]]>
        </Source>
      </Script>
    </Field>
  </Section>
  <Button action="next" label="Next"/>
  <Button action="back" label="Back"/>
</Form>

  1. Workflow example with form
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE Workflow PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<Workflow explicitTransitions="true" name="Sample Workflow">
  <Step icon="Start" name="Start" posX="28" posY="10">
    <Transition to="Sample Form Step"/>
  </Step>
  <Step icon="Stop" name="Stop" posX="256" posY="10"/>
  <Step icon="Default" name="Sample Form Step" posX="98" posY="10">
    <Approval name="Sample Workflow Form" owner="ref:launcher" return="" send="">
      <Form name="Sample Workflow Form">
        <Attributes>
          <Map>
            <entry key="pageTitle" value="Sample Workflow Form"/>
            <entry key="subtitle" value="Sample Workflow Form"/>
            <entry key="title" value="Sample Workflow Form"/>
          </Map>
        </Attributes>
        <FormRef name="Sample Workflow Form"/>
      </Form>
    </Approval>
    <Transition to="Stop"/>
  </Step>
</Workflow>
1 Like

Agreed with @kjakubiak, add on to a form template. Here is another example that uses a workflow step to add to a form as opposed to doing it directly inside the form itself. I used this before to add fields for each identity attribute.

<Step icon="Task" name="Build Form" posX="225" posY="25" resultVariable="inputForm">
  <Script>
    <Source><![CDATA[
      import sailpoint.object.Form;
      import sailpoint.object.Form.Section;
      import sailpoint.object.Field;
      import sailpoint.object.ObjectConfig;
      import sailpoint.object.ObjectAttribute;
      
      //Get Form and make a copy
      Form form = context.getObjectByName(Form.class, actionCodeFormName);
      Form formCopy = form.derive(context);
      context.decache(form);
      
      //Add identity attributes to section
      ObjectConfig objConfig = context.getObjectByName(ObjectConfig.class, "Identity");
      List extendedList = objConfig.getObjectAttributes();  
      
      Section attributeSection = formCopy.getSection("Section-IdentityAttributes");
      for (ObjectAttribute objAtr : extendedList) {
        Field currentValueField = new Field();
        currentValueField.setReadOnly(true);
        currentValueField.setName(objAtr.getName());
        currentValueField.setDisplayName(objAtr.getName() + " - Current Value");
        currentValueField.setColumnSpan(1);
        
        Field newValueField = new Field();
        newValueField.setName("new_" + objAtr.getName());
        newValueField.setDisplayName(objAtr.getName() + " - New Value");
        newValueField.setColumnSpan(1);
        
        attributeSection.add(currentValueField);
        attributeSection.add(newValueField);
      }
      
      return formCopy;
    ]]></Source>
  </Script>
  <Transition to="Input Form"/>
</Step>
2 Likes

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.