Skip Ribbon Commands
Skip to main content

Robin | zevenseas | SharePoint Blog

:

The zevenseas Community > Blogs > Robin | zevenseas | SharePoint Blog > Posts > Building a custom Nintex Workflow Activity : using the CredentialPicker
September 25
Building a custom Nintex Workflow Activity : using the CredentialPicker

In my previous post I mentioned that I also wanted to use the CredentialPicker from Nintex to include in my own custom activity and since of this week I finally managed to achieve this! ;)

What is the CredentialPicker? This picker allows you to set an username and password combination so that an activity can be ran using those credentials. But you can also use a lookup to a workflow constant credential that can be defined on web / site / web application level. So it’s like the SPSecurity.RunWithElevatedPriviliges method but then in a workflow activity. So I think you can see the potential of this control.. In an activity it looks like this :

credentialpicker

Doesn’t look that spectacular eh? But.. it’s very powerful.. very.. 

So how do we get this awesome little control in our dialog page?

  1. Add the UserControl declarative in the header of the page
    <%@ Register TagPrefix="Nintex" TagName="CredentialControl" Src="~/_layouts/NintexWorkflow/CredentialControl.ascx" %>
  2. Add the javascript code to retrieve the current set values using the TPARetrieveConfig method
    function TPARetrieveConfig() {           
    
        if (configXml.selectSingleNode("/NWActionConfig/Parameters/Parameter[@Name='Username']") && configXml.selectSingleNode("/NWActionConfig/Parameters/Parameter[@Name='Password']")) {
    
            cc_setUsername("<%= credentialPicker.ClientID %>", configXml.selectSingleNode("/NWActionConfig/Parameters/Parameter[@Name='Username']/PrimitiveValue/@Value").text);
    
            cc_setPassword("<%= credentialPicker.ClientID %>", configXml.selectSingleNode("/NWActionConfig/Parameters/Parameter[@Name='Password']/PrimitiveValue/@Value").text);
    
        }
    
    }
  3. Add the javacsript to write the current value set using the TPAWriteConfig method
    function TPAWriteConfig() {          
    
        EnsurePrimitiveValueNode(configXml, "Username");
    
        EnsurePrimitiveValueNode(configXml, "Password");
    
        configXml.selectSingleNode("/NWActionConfig/Parameters/Parameter[@Name='Username']/PrimitiveValue/@Value").text = cc_getUsername("<%= credentialPicker.ClientID %>");
    
        configXml.selectSingleNode("/NWActionConfig/Parameters/Parameter[@Name='Password']/PrimitiveValue/@Value").text = cc_getPassword("<%= credentialPicker.ClientID %>");
    
        return true;
    
    }
  4. And then we add the UserControl in the ContentPlaceHolder
     <Nintex:CredentialControl RequiredField="true" DisplayMode="dialog" CssClass="ms-input"
    
            Width="170px" runat="server" id="credentialPicker">
    
        </Nintex:CredentialControl>
  5. To get the credentials in codebehind in the CodeActivity use this
  6. string runtimeUsername = string.Empty;
    
    string runtimePassword = string.Empty;
    
    CredentialValue.DetermineRuntimeCredentials(
    
    this.Username, //UserName Property
    
    this.Password,  //Password Property
    
    out runtimeUsername, 
    
    out runtimePassword, 
    
    ctx.Web.ID, 
    
    ctx.Web.Site.ID);
    
    NetworkCredential credentials = null;
    
    if (runtimeUsername.Contains(@"\"))
    
    {
    
       string[] strArray = 
    
            runtimeUsername.Split(new char[] { '\\' });
    
       credentials = 
    
            new NetworkCredential(strArray[1], runtimePassword, strArray[0]);
    
    }
    
    else
    
    {
    
       credentials = new NetworkCredential(runtimeUsername, runtimePassword);
    
    }
 
Technorati Tags: ,,

Comments

Inkspot

Would you be willing to share an nintex installation wsp file of this. It's exactly what I need but I'm not exactly clear on how to build it for Nintex.
System Account on 07/12/2009 06:04

Inkspot

I'm sorry...I meant share it as a Nintex .NWA format.
System Account on 07/12/2009 08:28

Nintex User

Now what I would really would like to see is this feature rolled in with the Copy an Item action that Nintex offers as well. Up to the challenge... :-)
System Account on 13/12/2009 03:49

Another NintexUser

Better yet I think it would be nicer to see this with the Create an Item action that Nintex offers. I think this would be more powerful. How about that challenge..... :-) Also, Inkspot.....Robin was talking about including this in your own Custom Activity. You have to build your own and add this to it. Hope that helps.
System Account on 13/12/2009 03:54
 

 Statistics

 
Views: 3638
Comments: 4
Tags:
Published:1338 Days Ago