I found this response to one of the questions about substrings and replacing/truncating a specific number of strings. My question is, where do you put the code? Does it go with the config.json file? Thanks
Solved! Go to Solution.
Rudo,
Here is the updated function that should do what you are wanting. I am assuming that the field is a string based on the field content examples you have given. So in the Widget.js replace the existing _substitute function with this one.
_substitute: function (string, Attribs, currentLayer) { var lfields = this._getFieldsfromLink(string); for (var lf = 0; lf < lfields.length; lf++) { if (Attribs[lfields[lf]]) { var fld = this._getField(currentLayer, lfields[lf]); if (fld.type === "esriFieldTypeString") { if(lang.trim(lfields[lf]) === 'IncDate'){ var sYear = lang.trim(Attribs[lfields[lf]]).substring(0, 4); string = string.replace(new RegExp('{' + lang.trim(lfields[lf]) + '}', 'g'), sYear); }else{ string = string.replace(new RegExp('{' + lang.trim(lfields[lf]) + '}', 'g'), lang.trim(Attribs[lfields[lf]])); } } else { string = string.replace(new RegExp('{' + lang.trim(lfields[lf]) + '}', 'g'), Attribs[lfields[lf]]); } } } return string; },
Rudo,
Just in the Widget.js
You would need to look for more of our conversion (Kevin and I) on this topic:
https://community.esri.com/docs/DOC-1731#comment-20094
https://community.esri.com/docs/DOC-1731#comment-20171
https://community.esri.com/docs/DOC-1731#comment-20172
My link is looking at a {incdate} parameter within the url to open a report for different years. The {incdate} field is displayed like 20160203, I need the first 4 characters to get the correct year but get and error because it's gathering the whole string in the {incdate} field. Will this code allow me to do that?
Rudo,
Here is the updated function that should do what you are wanting. I am assuming that the field is a string based on the field content examples you have given. So in the Widget.js replace the existing _substitute function with this one.
_substitute: function (string, Attribs, currentLayer) { var lfields = this._getFieldsfromLink(string); for (var lf = 0; lf < lfields.length; lf++) { if (Attribs[lfields[lf]]) { var fld = this._getField(currentLayer, lfields[lf]); if (fld.type === "esriFieldTypeString") { if(lang.trim(lfields[lf]) === 'IncDate'){ var sYear = lang.trim(Attribs[lfields[lf]]).substring(0, 4); string = string.replace(new RegExp('{' + lang.trim(lfields[lf]) + '}', 'g'), sYear); }else{ string = string.replace(new RegExp('{' + lang.trim(lfields[lf]) + '}', 'g'), lang.trim(Attribs[lfields[lf]])); } } else { string = string.replace(new RegExp('{' + lang.trim(lfields[lf]) + '}', 'g'), Attribs[lfields[lf]]); } } } return string; },