4 Replies Latest reply: May 9, 2012 11:37 AM by user12836258 RSS

    Possible to Create File from Workflow?

    user12836258
      I'm trying to create a custom workflow that will pull the names of all users in a particular resource and write them to a file. Is this possible?

      If so, how would I first go about getting the names of all the users in my resource? Seems like it should be straightforward, but I'm not sure how to do it. Are there samples/examples anywhere that would show me how to do this?

      And then is it possible to write to a file in a workflow?

      Any tips, examples, pointers, are appreciated. Thanks!
        • 1. Re: Possible to Create File from Workflow?
          RK_IDM
          Here is how you will query users ...
          <set name='userList'>
            <invoke name='getUsers' class='com.waveset.ui.FormUtil'>
             <invoke name='getLighthouseContext'>
               <ref>WF_CONTEXT</ref>
             </invoke>
             <map>
               <s>conditions</s>
               <list>
                <new class='com.waveset.object.AttributeCondition'>
                 <s>user_resources</s>
                 <s>is</s>
                 <s>Your AD Resource</s>
                </new>
               </list>
             <map>
            </invoke>
          <set/>
          I usually put the below code somewhere at the beginning of my workflow to create an output file. This helps me overwrite the file if it exists already
          <Action id='0'>
            <expression>
              <invoke name='writeFile' class='com.waveset.util.Util'>
                <s>myFile.txt</s>
                <s></s>
              </invoke>
            </expression>
          </Action>
          And I finally use this piece of code to keep appending to the same output file ...
          <Action id='0'>
            <expression>
              <block>
                <invoke name='appendFile' class='com.waveset.util.Util'>
                  <ref>myFile.txt</ref>
                  <concat>
                    <ref>idmAccount</ref>
                    <s>|</s>
                    <ref>adAccount</ref>
                    <s>|</s>
                    <ref>adPath</ref>
                    <s>|</s>
                    <ref>errorMessage</ref>
                  </concat>
                </invoke>
            </block>
            </expression>
          </Action>
          • 2. Re: Possible to Create File from Workflow?
            user12836258
            Thank you! That's exactly what I needed. The code makes sense and I was able to make it work to a certain extent. What I'm struggling with now is how to have the actions work on each user I get back from my search.

            I'm pretty new to writing workflows (obviously :) ). I'm missing some important piece. Right now I have my workflow - it calls the rule and I get back a list of users in my resource. Then I want to get some attributes for each user and write them to the file but I can't wrap the activities/actions in a do loop because that's not allowed. How should I structure this to get it to do what I need? How do I tell the workflow to run once per user? Do I need a form? And if so, how will kick this process off when I need the file? I was hoping for a weekly scheduled task.

            Any ideas are welcome. Thanks!
            • 3. Re: Possible to Create File from Workflow?
              RK_IDM
              I am not an expert either. Hope this helps.
              <?xml version='1.0' encoding='UTF-8'?>
              <!DOCTYPE TaskDefinition PUBLIC 'waveset.dtd' 'waveset.dtd'>
              <TaskDefinition name='Query Users' taskType='Workflow' executor='com.waveset.workflow.WorkflowExecutor' suspendable='true' 
                syncControlAllowed='true' execMode='sync' execLimit='0' resultLimit='0' resultOption='delete' visibility='runschedule' progressInterval='0'>
                <Extension>
                  <WFProcess name='Query Users' maxSteps='0'>
                    <Variable name='userList'/>
                    <Variable name='userId'/>
                    <Variable name='resourceId'>
                      <s>AD Resource</s>
                    </Variable>
              
                    <Activity id='0' name='start'>
                      <Transition to='Get Users'/>
                    </Activity>
              
                    <Activity id='1' name='end'>
                    </Activity>
              
                    <Activity id='2' name='Get Users'>
                      <Action id='0'>
                        <expression>
                          <set name='userList'>
                            <invoke name='getUsers' class='com.waveset.ui.FormUtil'>
                              <rule name='AW User Library:Get Context'/>
                              <map>
                                <s>conditions</s>
                                <list>
                                  <new class='com.waveset.object.AttributeCondition'>
                                    <s>user_resources</s>
                                    <s>is</s>
                                    <ref>resourceId</ref>
                                  </new>
                                </list>
                              </map>
                            </invoke>
                          </set>
                        </expression>
                      </Action>
                      <Transition to='end'>
                        <isnull>
                          <ref>userList</ref>
                        </isnull>
                      </Transition>
              
                      <Transition to='Write To Report'/>
                    </Activity>
              
                    <Activity id='3' name='Write To Report'>
                      <Action id='0' name='Create Output File'>
                        <expression>
                          <invoke name='writeFile' class='com.waveset.util.Util'>
                            <s>e:/RunTimeOutput/UserReportWithDateLastLogin.txt</s>
                            <concat>
                              <s>User ID</s>
                              <s>|</s>
                              <s>First Name</s>
                              <s>|</s>
                              <s>Last Name</s>
                              <s>Insert Newline character Here</s>
                            </concat>
                          </invoke>
                        </expression>
                      </Action>
                      <Transition to='Process Users'/>
                    </Activity>
              
                    <Activity id='4' name='Process Users'>
                      <Variable name='counter' value='0'/>
                      <Variable name='user'/>
                      <Variable name='lastLoginDate'/>
                      <Action id='0' name='Process Users'>
                        <expression>
                          <while>
                            <lt>
                              <ref>counter</ref>
                              <length>
                                <ref>userList</ref>
                              </length>
                            </lt>
                            <block>
                              <set name='userId'>
                                <get>
                                  <ref>userList</ref>
                                  <ref>counter</ref>
                                </get>
                              </set>
                              <set name='user'>
                                <invoke name='getView'>
                                  <rule name='AW User Library:Get Context'/>
                                  <concat>
                                    <s>User:</s>
                                    <ref>userId</ref>
                                  </concat>
                                  <map>
                                    <s>authorized</s>
                                    <s>true</s>
                                    <s>Form</s>
                                    <s>Empty Form</s>
                                    <s>TargetResources</s>
                                    <list>
                                      <s>Lighthouse</s>
                                      <ref>resourceId</ref>
                                    </list>
                                  </map>
                                </invoke>
                              </set>
                              <invoke name='appendFile' class='com.waveset.util.Util'>
                                <s>e:/RunTimeOutput/UserReportWithDateLastLogin.txt</s>
                                <concat>
                                  <ref>userId</ref>
                                  <s>|</s>
                                  <ref>user.accounts[Lighthouse].firstname</ref>
                                  <s>|</s>
                                  <ref>user.accounts[Lighthouse].lastname</ref>
                                  <s>Insert Newline character Here</s>
                                </concat>
                              </invoke>
                              <setvar name='user'>
                                <null/>
                              </setvar>
                              <set name='counter'>
                                <add>
                                  <ref>counter</ref>
                                  <i>1</i>
                                </add>
                              </set>
                            </block>
                          </while>
                        </expression>
                      </Action>
                      <Transition to='end'/>
                    </Activity>
                  </WFProcess>
                </Extension>
                <MemberObjectGroups>
                  <ObjectRef type='ObjectGroup' id='#ID#Top' name='Top'/>
                </MemberObjectGroups>
              </TaskDefinition>
              New Line Tag: <&#xA;> (Use without the < and > signs)
              • 4. Re: Possible to Create File from Workflow?
                user12836258
                Thank you very much for the help! I was able to get it working and learned quite a bit along the way. (always a good thing).