Livelink Object from Work Flow Form

On many occasions there are times when you want to snapshot the status of a Livelink workflow Form data at a given point in the work, either for auditing or for archiving. The following Event Script creates a Livelink Form Object using a specified Form Template and View and creates it in a specified folder in Livelink.
This snippet comes in two sections, the first is the main Event Script (CreateLLObjFromForm) which acts as the wrapper, and a second OScript Script (CreateFormNode) which creates the Livelink Object. This second method does not have to sit within the same Script as the main event script, so could be placed elsewhere in your module.

In the first script, the output folder specfied by its Livelink Node ID (DTree.DataId), although in a production environment you may want to have this loaded from the Workflow Form, database table or ini file rather than being hardcoded. Next we load the Workflow itself and get the Forms package and grab the Form Template, the code assumes that we will always use the first template in the workflow, then we gather the values needed to create the Livelink Object and call the second method. A commented version of this Event Script is shown below :

 Text |  copy code |? 
01
Function Dynamic CreateLLObjFromForm( \
02
    Object	 prgCtx, \
03
    WAPIWORK	work, \
04
    Integer	 workID, \
05
    Integer	 subWorkID, \
06
    Integer	 taskID, \
07
    Integer	 returnSubWorkID, \
08
    Integer	 returnTaskID, \
09
    Dynamic	 extraData = Undefined )
10
 
11
    // stick the current user context into a variable
12
    Object tempPrgCtx = prgCtx
13
 
14
    // create a new context as Admin to avoid Permissions/Rights issues
15
    String cnctName = $Kernel.SystemPreferences.GetPrefGeneral( 'DftConnection' )
16
    Assoc prgAssoc = $LLIApi.PrgSession.CreateNewNamed(cnctName,{"Admin",undefined})
17
    prgCtx = prgAssoc.pSession // dump the prog context into a Feature so it can be read elsewhere
18
 
19
    // other variables
20
    DAPINode templateNode, outputNode
21
    Assoc	retval = Assoc.CreateAssoc()
22
    retval.OK = true
23
    record r
24
    boolean found = false
25
    Integer outputFolder=2000 // Create in the Container with DataID 2000
26
 
27
    // Get the Form data from the workflow
28
    Object obj = $WFMain.WFPackageSubsystem.GetItemByName( 'Form' )
29
    // Load the work package
30
    RecArray array = $WFMain.WAPIPkg.LoadWorkData( prgCtx, work )
31
 
32
    // if we have loaded the Forms Package
33
    if ( IsDefined( obj ) )
34
        // find the Form Template Node
35
        for r in array
36
            if ( { r.TYPE, r.SUBTYPE } == { obj.fType, obj.fSubType } )
37
                found = True
38
                templateNode=DAPI.GetNodeByID(prgCtx.DSession().fSession,DAPI.BY_DATAID,r.USERDATA.AvailableForms[ 1 ].TemplateID)
39
                break
40
            end
41
        end
42
 
43
        // We have found the form containing the data 
44
        if ( found )
45
            // grab the node to put the data in 
46
            outputNode = DAPI.GetNodeByID(prgCtx.DSession().fSession,DAPI.BY_DATAID,outputFolder)
47
            // if we have the Output Folder
48
            if ((isDefined(outputNode)) && (!IsError(outputNode)))
49
                String formName=r.USERDATA.Forms[1].Name // get the name of the Form
50
                Integer templateID=r.USERDATA.Forms[1].TemplateID // get the DTREE.DATAID of the Template
51
                Integer templateVersion=templateNode.pVersionNum // get the version number of the Template
52
                // create the Form Node
53
                retval = CreateFormNode(prgCtx,formName,outputNode,r.USERDATA.Forms[1],templateID,templateVersion)
54
            end
55
        end
56
    end
57
 
58
    //reset orginal prgctx before we leave
59
    prgCtx = tempPrgCtx
60
    Echo( 'LEAVE SAVEFORM' )
61
    Echo( Str.ValueToString( retval ) )
62
    return retval
63
end

This helper function creates the actual HTML Form Node in Livelink. This script generates a unique name for the new object using the provided Form Name and the current date and time stamp. Once the node is created, we specify which Form View we wish to use for the new Node, this allows us to specify a custom or read only Form View for example. Then we create the Node and populate it with the information from the workflow to complete the activity. The commented code is shown below :

 Text |  copy code |? 
01
Function Assoc CreateFormNode( Object prgCtx, String formname, DAPINode parentNode, Assoc formData, Integer templateId, Integer templateVersion = undefined )
02
    Assoc CreateInfo, retVal
03
    retVal.ok = true
04
 
05
    // firstly, grab the correct LLNode for a webform
06
    Object llNode = $LLIAPI.LLNodeSubsystem.GetItem($TypeForm)
07
 
08
    // if we have an LL Node Object
09
    if( IsDefined( llNode ) )
10
        // create a unique object name using the Form Name and the Date
11
        String newFormName=Str.Format("%1 - Form - %2",formname, \
12
              Date.DateToString(CAPI.Now(prgCtx.fDBConnect.fConnection),"%d.%m.%Y %H.%M"))
13
        // Allocate a new node in the parent container
14
        Assoc status = llNode.NodeAlloc( parentNode, newFormName )
15
        // if the node was created correctly
16
        if(status.OK)
17
            // populate the properties for creation of the Form
18
            createInfo.FormView ='View One' // use the View called View One
19
            createInfo.SubmitMech = 0
20
            createInfo.storageMech = 1
21
            createInfo.TemplateID = templateId
22
            createInfo.TemplateVersion = templateVersion
23
            createInfo.LL_TemplateVersion = templateVersion
24
 
25
            // Create the node in the parent container using the properties specified
26
            status= llNode.NodeCreate( status.Node, parentNode, createInfo)
27
 
28
            // if the node was created correctly
29
            if(status.OK)
30
                // These two values need to be in the formData 
31
                formData.LL_TemplateVersion = templateVersion
32
                formData.DataAssoc= formData.Data.DataAssoc
33
                // Stream the Node
34
                status = $LLIApi.NodeUtil.StreamValToNode( status.Node, "FormData", Str.ValueToString( formData ), 1, 1 )
35
                // If there was an error creating the node
36
                if (!status.ok)
37
                    retVal.ok = false
38
                    Echo( 'Error adding the formdata version!' )
39
                    Echo( status.errMsg )
40
                end
41
            else
42
                retVal.ok = false
43
                Echo( 'Error Creating the Form Node!' )
44
                Echo( status.errMsg )
45
            end
46
        else
47
            retVal.ok = false
48
            Echo( 'Error Allocating the Form Node!' )
49
            Echo( status.errMsg )
50
        end
51
    end
52
    return retVal
53
end

source: http://www.greggriffiths.org/livelink/development/oscript/eventscripts/llobjfromform.html

  • Share/Bookmark
No Responses to “Livelink Object from Work Flow Form”

Post a Comment