Search This Blog

Saturday, 26 February 2011

Browser Enabled Infopath with PeopleEditor Control

Req: My req was to have multiple People Picker on Infopath form as below in snapshot.

Steps Carried out:

Step 1: In right Panel of Infopath go to "Add or Remove Custom Controls"
        - Click Add
        - Select Active -x
        - Select 'Contact Selector'
        - Select Don't include .CAB file
        - From dropdown select 'Field or Group(any data type)
        - Click Finish

Step 2: To create DataSource for Contact Selector
           - Add non repeating group 'group1'
           - Add repeating group 'Person'
           - Add 3 text fields ''DisplayName, 'AccounId', 'AccountType'

[Refer Snapshot]

Step 3: To add MORE THAN ONE people picker on the form

         - Create new group for new selector following same step as in Step2 name it as 'group2'
        - Now right click on existing 'Person' of group1 and select 'reference' and then select newly creatd  group that is 'group2'.
         - Similar xml structure will get copied. Follow same for the the rest.

Step 4: Drag all the contact selectors on the form

Step 5: Adding of Secondary Datasouce that is Context.xml which has Information of SharePoint Server to validate users against it.

       - In notepad type
<Context siteUrl="http://<yourserverername>" />

     - Save file as 'Context.xml'.
     - Create new DataConnection of 'Receiving type' and Source of data as 'XML'
     - Enabe option 'Include the data as resource file'.

-- Aks
----down select "Field or Group(any data type) and click finish From drop down select "Field or Group(any data type) and click finish
From drop down select "Field or Group(any data type) and click finish

Infopath Form and Sharepoint Designer Workflow

Req: To design form using Infopath which can be used by user to fill inforamtion and then to have 3 levels of approval workflow.

Workfow: Designed using Sharepoint designer.

[Refer Snaphot]

Step 1: Design form Using Infopath the you require. I created Tab structure for easy navigation and also designed Save, Submit, Previous and Next button

Step 2: Publish the form to the form library.

Since I wanted to create Save functionality where user can Just Save the form in Draft mode. I published the form in two different Form library, one 'Save Draft' for Saving Draft for further modifications and one 'Submit Form' for Submitting where workflow of approval was attached.

   Initially when user fills the form half-way and not completly , user can click Save button . Its gets Saved to 'Save Draft' library. Later user wants to Submit the form, user can open the from and click Submit which gets submitted to 'Submit Form' library and workflow triggers.

   Once workflow triggers, we can delete the corresponding form 'Save Draft' library as its has been submitted for approval. This deletion can be done using SPD workflow attached to 'Submit Form' library.

Step 3: Using SPD create approval workflow attached to 'Submit Form' Library.

Suppose we have 3 approval groups
 a. PO
 b. Reviewer
 c. BFM

Before that create on 'Status' column in 'Submit Form' library as choice type, with following options
2.Approved by PO
3.Rejected by PO
4.Approved by Reviewer
5.Rejected by Reviewer
6.Approved by BFM
7.Rejected by BFM

So workflow conditions can be as mentioned below.

Condtion :If status is Pending
Action: Send Email to PO for approval /Reject
           then Wait for Status to be not Pending

Level 2:
Condition: It Status is 'Approved by PO'
Action: Send Email to Reviewer //for second level
            then stop the workflow

else If Status is 'Rejected by PO'
Action : Send Email to user
             then stop the workflow

Level 3:
Condition: It Status is 'Approved by Reviewer'
Action: Send Email to BFM //for third level
            then stop the workflow

else If Status is 'Rejected by Reviewer'
Action : Send Email to user
             then stop the workflow

Level 4:
Condition: It Status is 'Approved by BFM'
Action: Send Email to user // Indication it is approved
            then stop the workflow

else If Status is 'Rejected by BFM'
Action : Send Email to user
             then stop the workflow

-- Aks

Friday, 25 February 2011

To Copy Items from one SharePoint List to another SharePoint List making .exe

SharePoint PeoplePicker in

PeoplePicker can be added at runtime using PeopleEditor class.

PeopleEditor projectManager = new PeopleEditor();

//To insert value in SharePoint List

We need to create SPUser object
SPUser objUser = SPContext.Current.Web.User[peopleContact.CommaSeparatedAccounts];
String strUserToInsert = objUser.ID + ";#" + objUser.Name;
item["ProjectManager"] = objUser; // ProjectManager ---> Column in List

//To derive EmailId of ProjectManager
string projectmanagerEmailId = objUser.EmailId.ToString();

//To derive LoginId of ProjectManager
string loginProjectManager = objUser.LoginID.Tostring();

Similarly other details can be fetched.

//Important Properties

1.  projectManager .MultiSelect = true or false;  //Allows either multiple selection of users or single selection user.

2. projectManager.AllowTypeIn = true or false //to specify if the user can type the user name in the text box, or if he must use the browse window popup


DateTime Control in .net and Javascript validation for the same

Recently I had an requirment of validation or checking DatePicker for null or empty using Javascript.

My DatePicker was created on runtime using below code.

DateTimeControl StartDate = new DateTimeControl();

First I tried writing on Submit button, [this is wriitrn in .net and Javascript is called inside .cs using onclick event of button]

lbl_Submit.Attributes.Add("onClick", function checkStartDate() {if(document.getElementById(" + StartDate.ClientID + ").value==''){msg = msg + 'Please Select Start Date'; alert('msg'); return false;};};return checkStartDate(););

Here StartDate.ClientDate gives ID of DateTimeControl , but this validation was not working . ;(

Then I found that, DateTimeControl is made up of two parts, one is Textbox and other part is calander.

So if you want to check for null value ,you need to take ClientId of Textbox instead of entire control.

This can be done as shown below.

StartDate.Control[0].ClientID // This works fine.

Here Control[0] ---> indicates index of Textbox

So final code would be

lbl_Submit.Attributes.Add("onClick", function checkStartDate() {if(document.getElementById(" + StartDate.Control[0].ClientID+ ").value==''){msg = msg + 'Please Select Start Date'; alert('msg'); return false;};};return checkStartDate(););


Validation Textbox for Positive Real Numbers using Javascript on Submit button

1.Textbox pid = new Textbox();
2. Button lbl_Submitt = new Button();

lbl_Submit.Attributes.Add("onclick", function checkfornumber() {var msg=''; if(isNan(document.GetElementById("pid.ClientID").value=='')) {msg ='Please Eneter Positive Real Numbers'; alert(msg); return fase;}}return checkfornumber(););

isNan() ; // Checks weather input is number or not

Creating .net user form and Integrating into Sharepoint to save data in sharepoint list as database.

Step 1. This form may contain Textboxes, ListBoxes, PeopleEditor Control, DatePicker, Upload button for Attachments etc. [Refer SnapShot]


Step 2. Just create simpe .cs (codebehined) without design and compile the dll into webpart and put the dll into inetpub bin foder.

Step 3. The form will appear  on the sharepoint page.

In the above form I have created all the controls at runtime.

eg. 1. For Textbox

Texbox projectId = new Texbox();

2. For PeopleEditor

PeopleEditor pm = new PeopleEditor();

3. For Calendar

DateTimeControl StartDate = new DateTimeContro();

4. For Attachments;

FileUpload att = new FieUpload();

Once you Initialize the Contols , you can add them in between your Htmls