Jump to content

Drop down List with Open Text Choice


Recommended Posts

Hi,

 

I'm trying to figure out if there is an easier way to accomplish what we are doing. Example...we are working on Memorial Day postcard and there is a data field Header and we also offer HeaderCustom field (in case user doesn't want to use our pre-written copy they can add their own). Then we have Copy and CopyCustom and so on. On Marcom Side this needs to be a drop down for user to either pick our copy or Custom. Right now we are using .txt file and uploading to MarcomCentral and creating drop down list with the value to pull from that XDF file... the rule looks something like this...

 

 

Header = "";

 

var XDF = new ExternalDataFileEx("PostcardContent.txt", "\t");

 

for (i = 1; i < XDF.recordCount+1; i++)

{

Option = XDF.GetFieldValue(i, 0);

 

{

if (Field("Header") == Option)

 

{

Header = XDF.GetFieldValue(i, 1);

}

}

 

}

 

return Header;

 

 

and...

 

var var1 = Rule("Rule HeaderContent");

var var2 = Field("HeaderCustom");

 

 

if (var1=="") {

var1 = var2;

} else {

var1 = var1;

}

 

return var1;

 

 

Is this the best practice for what we are doing or is there another way this can be done without XDF file maybe? Thank you,

Link to comment
Share on other sites

Because your site is sending back the "option" the user selected rather than the value of the option the user selected, I think you'll have to continue referencing the external data file.

 

That being said, you can certainly simplify things. You consolidate your two "header" rules into one:

var XDF = new ExternalDataFileEx("PostcardContent.txt", "\t");
return XDF.GetFieldValue(XDF.FindRecord(0, Field('Header')), 1) || Field('HeaderCustom');

The above code will search for a value in the first column of your data file that matches the value of the "Header" field. If found, the corresponding value of the second column will be returned. If nothing is found, it will return the value of the "HeaderCustom" field.

 

I set that up in accordance to the rule you supplied but I would think the value of the custom field would take precedence over the pre-written options. If that's the case, you can just reverse the order:

var XDF = new ExternalDataFileEx("PostcardContent.txt", "\t");
return Field('HeaderCustom') || XDF.GetFieldValue(XDF.FindRecord(0, Field('Header')), 1);

Link to comment
Share on other sites

That being said, you can certainly simplify things. You consolidate your two "header" rules into one:

var XDF = new ExternalDataFileEx("PostcardContent.txt", "\t");
return XDF.GetFieldValue(XDF.FindRecord(0, Field('Header')), 1) || Field('HeaderCustom');

 

 

OK got stuck with this lol...Is it possible to add a replace substring to the code above? I know how to do this as two separate rules, but can it be done as one to simplify code further?

This is what I have for HeaderReplace rule...

 

var s = Rule("Rule Header");

 

s = ReplaceSubstring(s, "[COMMUNITY NAME]", Field("Community Name"));

s = ReplaceSubstring(s, "[RSVP]", Field("RSVPPhone"));

return s;

Link to comment
Share on other sites

var XDF = new ExternalDataFileEx("PostcardContent.txt", "\t");
var s = XDF.GetFieldValue(XDF.FindRecord(0, Field('Header')), 1) || Field('HeaderCustom');
s = ReplaceSubstring(s, "[COMMUNITY NAME]", Field("Community Name"));
s = ReplaceSubstring(s, "[RSVP]", Field("RSVPPhone"));
return s;

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...