| 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 : 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? - Add the UserControl declarative in the header of the page
<%@ Register TagPrefix="Nintex" TagName="CredentialControl" Src="~/_layouts/NintexWorkflow/CredentialControl.ascx" %>
- 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);
}
}
- 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;
}
- 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>
- To get the credentials in codebehind in the CodeActivity use this
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);
}
|