indumglynndevins.com Posted April 20, 2018 Share Posted April 20, 2018 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, Quote Link to comment Share on other sites More sharing options...
step Posted April 20, 2018 Share Posted April 20, 2018 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); Quote Link to comment Share on other sites More sharing options...
indumglynndevins.com Posted April 23, 2018 Author Share Posted April 23, 2018 Thank you Step! That's good to know. Quote Link to comment Share on other sites More sharing options...
indumglynndevins.com Posted April 23, 2018 Author Share Posted April 23, 2018 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; Quote Link to comment Share on other sites More sharing options...
step Posted April 23, 2018 Share Posted April 23, 2018 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; Quote Link to comment Share on other sites More sharing options...
indumglynndevins.com Posted April 23, 2018 Author Share Posted April 23, 2018 Thank you once again...I was so close LOL Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.