Skip to main content

I'm initiating a workflow with an InfoPath form which populates a SmartObject. I have created a second form for the approval client event. What I want is for this form to be pre-populated with the data submitted in the first form, so that the approver can see what they are approving. I have integrated the load method of the SmartObject with the form, and call this when the form loads using a rule. However this gives an error when the forms opens "Some rules were not applied.". The question is how should I be going about populating the form data from information previously submitted? Using the single load method, how does Blackpearl know which row in the SmartObject it should be loading? Or do I need to fetch the ID from the SmartObject when the first form submits, and then pass this into the second form in an XML field or something, to then query the SmartObject with?


 Thanks for any help

The first time the form is submitted you probably call the create method on your smart object. You should then store the return value from the create (which is the primary key of your SO) in an infopath data field (on your primary data source). Then when you call the load method you use that primary key value from your infopath data source to call load.


Hope that makes sense. :)


Cheers,


 


Thanks. That is similar to what I am trying to do but I am a bit stuck implementing it. I have just tried setting the default values on the fields to call the various load methods from the SmartObject but with no success.


 I have modified my first form by adding a field under the _K2 group under the Main data source (is this correct?). Then I have a submit rule that sets the value of that field to be equal to the Id field in the form (again, is this the correct way to go about it?).


In my second form, how do I use this Id value in the SmartObject load?


 Thanks for your help so far


I would not add the field under the _K2 group - that group should be managed by the K2 designer only so I'd suggest to not add your own fields in there, but do it on root level of the main data source. Then you want to set that field equal to the return value of the create call on your smart object.


Furthermore I don't know if it's possible in your requirements, but if you can use one InfoPath form and multiple views on the form. That way the return value that you store in the form will automatically be available in the next view where you call the load method of the SO. In other words you will have two views instead of two forms. In the first view you capture the details into your SO using the create method. In the next view you display these details using the load method.


If you use two different forms you will have to copy that ID value from the one form to the other one... probably somewhere in your process.


HTH,


I would prefer to use one form with two views but I don't think this is possible is it? The reason being that I need to use the submit rules to populate the SmartObject (in which case it is populated twice - once from being submitted by the user and again when approved by the approver), and similarly the open rules need to be used for populating the field with the data from the SmartObject. I'd need a way to restrict the open and submit rules to work only with a certain view and I can't see a way to do that.

Yeah I know what you mean - your rules will be a bit more complicated, but you can have a look at the default rules that K2 generates for you for the different views and duplicate those kind of rules. I can't remember of the top of my head where, but I think it's in the form open rules. Have a look at that maybe.


Ciao,


 


I did a guide a while back that may have useful content for this discussion.


http://blog.mgallen.com/?p=143


 It basically explains how to load SO data into infopath after it's been modified in the workflow... but it may prove useful.


Martin


Great stuff Martin, I think that explains it very well!
Thanks Martin. I have been trying to do a similar thing but whenever I use the load method I don't get asked for any input parameters. The problem I'm having is getting Blackpearl to know what to return. The rule doesn't error but no data is populated in the form.

Ahh right.. InfoPath won't ask you for input parameters, you need to create another action in your rule. This action will set a value of a field, and the field will be the data connection to your smartobject that requires the input.


Hope that helps


Martin


I kind of understand what you mean. What I have done so far is as follows. I have a form with two views, one for submitting and one for approval. For my submit rules I have a rule to create the data in the SmartObject, and another to set a field in my form called 'smartObjId' which sets it equal to the 'id' field in the InputProperties from the create method of the SO which is an autonumber (maybe the autonumber doesn't exist in this field at this point?)


For my open rules I call the load method on the SO but I'm not entirely sure how to do this with the smartObjId field. Am I right that if I create a rule and then add an action to set a field equal to the value of smartObjId this is used in the next action which calls the load method? Also I'm not really sure why I need to set a fields' value here when the Id for the form is already in that field.


Okay I'll be more detailed.


You've got a smartobject that returns an autonumber... cool that's pretty straight forward.


What I have done in the past, is create a hidden text box control. When you've called the create method on the smartobject that returns the autonumber you can then assign the return to your hidden text box (as part of the rule). This is the 'datafields' section (http://blog.mgallen.com/wp-content/uploads/2008/02/tutorial8.jpg)... and it should contain the return autonumber


When you call the load method, you need to



  1. Set the value of the inputproperties autonumber to be the value in your hidden text box (http://blog.mgallen.com/wp-content/uploads/2008/02/tutorial7.jpg)
  2. Then call the load method

You should then be able to retireve the data successfully.


The first thing to do is to verify that you can retrieve the autonumber from your SO...


Martin


Thanks Martin I think I understand now. I'll give it a go and see what happens.

I have had a go at this but am now encountering errors with the form. This is what I have done so far:


 On my form submit rules I have a rule to call the create method, followed by a rule which sets the value of a hidden field to be equal to the value of 'Id' from the datafield return properties of the create method.


 On my form open rules I have a rule which as the first action sets the input properties 'Id' value to the equal to the hidden field. Then I have an action to call the load method.


 This is how I understood your explanation, but it's erroring when the form loads saying that not all rules could be applied.


Right, after some troubleshooting I have found it is erroring because there is no value in the hidden field. I added a default value to the hidden field and that prevents the form erroring when opened. However this means that assigning the return property to the hidden field is not working for some reason.

In what order are you assigning the value?


It should be - call create method, and then set the field value.


Alternatively you could try binding the hidden control to the datasource.


Martin


Thanks. The databinding was the problem. I still had the controls on the approval view bound to create instead of load. I am now able to retrieve data but only from the default value in smartObjId. I can't seem to set this when the form is submitted. I am using a rule of:


 Set a field's value: smartObjId = id


 Where id is an autonumber in the return properties of the create method. My rules are ordered as follows:


 Submit Workflow


Create SO data


Set Id


Ahh I think I see your problem.


The last action that the form performs should be the 'Submit Workflow' action. Put your own rules before that and this will ensure your rules are actioned. If you take a closer look at the K2 rule, you'll see that this is set to close the form and not run any further rules... if my memory serves me correctly.


Martin


Thanks I'll give that a try. It does still add data to the SmartObject despite that rule being after Submit Workflow. I did that deliberately to avoid adding data to the SmartObject if there was a problem submitting, but then I guess that doesn't really matter when there will be a unique ID for the item. I'll give it a go and let you know!

Martin you were correct! Adding the rule before the Submit Workflow rule does the trick.


 Thanks very much =)


Another quick question on this. Everything is working fine, but now I want to access the SO data again in other events later in the workflow. I am accessing the Id through the InfoPath XML fields and that is fine, bar one problem.


What happens is that my submit rules add the data to the SO and then set a hidden field to contain the Id so I can access the data in the approval view. When the approval occurs the form is submitted again and this runs the submit rules again, so when approving the current item is also adds more data to the SO and sets the Id to be the next autonumber, ie the Id that I obtain later in the workflow has been incremented by one and those rows in the SO are null/default values.


Is there a way I can only run rules in certain views? I can't see a way to do this other than maybe set up another hidden field with a value of say 0, then add a rule which sets it to 1 when the form is submitted. Then as a condition for the 'Add data to SO/Set Id' rule I'd set it to only run when the field has value 0. Seems messy so I'll try it but wondering if there is a better way.


Hi - yes this is very possible


You need to specify a rule condition. If you look at how the built in K2 ones work, they will check to see what view is enabled before they perform each action.


In the rule, you can say, if 'MyViewName' = '_K2.CurrentView' then perform rule. Its stored as part of the _K2 fields in your infopath form.


This value is set by K2 when it creates the ActivityDestinationInstance of your form, so you could if you wanted, write your own code to set another InfoPath form of your choice.


Hope that helps


Martin


That worked perfectly. Thanks again.

Hi,


Please assist in the following problem...in the infopath form.


I got a text box where i will be typing the 3 to 4 charaters and click search button to get the search results.


I am struggling with the rule.


Please tell me what rule i need to keep to working my button rule to work.


Please assist urgently. Thanks in advance.


The problem is


The Infopath form is working perfectly fetching all the users in the active directory.


I got like this


 Text box


Search button


Dropdown with all active directory users.


 In the button i kept the following action in the rule..


1. Set a field's value as


field = datasource is AD_User_Get_Users(Secondary)


Queryfileds>InputProperties>Name


Field = Name


Value = concat(*,TextBoxField,*)


amd also added a query


Ad_User_Get_Users


so i added 2 actions


one is field value and second is query.


but when on running, i can see users in the dropdown on loading form, when type something in text box and click search , i see the dropdown users vanish. so it is not searching by the textbox characters.


Please assist me in configuring correct rule i need to use to get search results in the dropdown.


 Thanks


Ravi


Reply