jamesAtSunGardPS
Newbie
Posts: 5
Joined: Thu Apr 28, 2016 11:45 pm

Conditional Adapter

Tue May 03, 2016 4:21 am

I'm prototyping an interface to a CRM system and one thing I need to do is to validate certain keywords (Client ID, Case #, etc).

Right now, I have a test model that looks like

SIML Code

<Model>
      <Pattern>(CUSTOMER|CLIENT) @CUSTOMERID</Pattern>
      <Response>
        <Think>
	        <Bot Set="CustomerName">
	          <CRM:CustomerID>
	            <Match Index="2" />
	          </CRM:CustomerID>
	        </Bot>
        </Think>
        <If Bot="CustomerName" Value="Unknown">I can't find that Customer</If>
        <Else>Customer set to <Bot Get="CustomerName" /><Think><Bot Set="CustomerID"><Match Index="2" /></Bot></Think></Else>
      </Response>
     </Model>
Where <CRM:CustomerID> is hook back into a C# Adapter that does a lookup. This works, but seems a tad convoluted.

Is there a way to extend the Variable space (User, Bot, Custom, CRM, etc) to call back to C#?

Or, to put it more generically, is there a better way to attack this?

Thanks,
James

User avatar
Leslie
Lead Software Architect
Posts: 377
Joined: Fri Sep 14, 2012 12:20 pm
Contact: Website

Re: Conditional Adapter

Tue May 03, 2016 9:26 pm

Well since you've already created an Adapter, maybe letting it handle all the complex part would make things simpler.

SIML Code

<Model>
      <Pattern>(CUSTOMER|CLIENT) @CUSTOMERID</Pattern>
      <Response>
        <CRM:CustomerID Value="{Bind Match:2}" />
        <If User="CustomerValidated">Customer set to <User Get="CustomerName" /></If>
        <Else>I can't find that Customer</Else>
      </Response>
    </Model>

CSharp Code

public class CustomerID : IAdapter
{
	public bool IsRecursive => true;

	public XName TagName => "CustomerID";

	public string Evaluate(Context context)
	{
		var valueAttribute = context.Element.Attribute("Value").Value;

		//Find the CustomerName using the Value

		//If Customer found set CustomerName and CustomerValidated variables.
		context.User.Settings["CustomerName"].Value = "Something";
		context.User.Settings["CustomerValidated"].Value = bool.TrueString;

		return string.Empty;
	}
}

jamesAtSunGardPS
Newbie
Posts: 5
Joined: Thu Apr 28, 2016 11:45 pm

Re: Conditional Adapter

Wed May 04, 2016 6:11 am

Perfect, thanks!

Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 2 guests