Copy link to clipboard
Copied
 
This field (Summary of Services) generated from many textfields. I mean I can't access to delete the empty lines manually.
So if there is a code or a way I can delete these empty lines this will be great.
Ans this is the script I used:
// Get the field values, as strings
var s1 = getField("Hob.1").valueAsString;
var s2 = getField("Hob.2").valueAsString;
var s3 = getField("Hob.3").valueAsString;
var s4 = getField("Hob.4").valueAsString;
var s5 = getField("Hob.5").valueAsString;
var s6 = getField("Hob.6").valueAsString;
var s7 = getField("Hob.7").valueAsString;
var s8 = getField("Hob.8").valueAsString;
var s9 = getField("Hob.9").valueAsString;
var s10 = getField("Hob.10").valueAsString;
var s11 = getField("Hob.11").valueAsString;
var s12 = getField("Hob.12").valueAsString;
var s13 = getField("Hob.13").valueAsString;
var s14 = getField("Hob.14").valueAsString;
var s15 = getField("Hob.15").valueAsString;
var s16 = getField("Hob.16").valueAsString;
var s17 = getField("Hob.17").valueAsString;
var s18 = getField("Hob.18").valueAsString;
var s19 = getField("Hob.19").valueAsString;
var s20 = getField("Hob.20").valueAsString;
// Combine values, separated by a space
event.value = s1+ "\n" + s2+ "\n" +s3+ "\n" +s4+ "\n" +s5+ "\n" +s6+ "\n" +s7+ "\n" +s8+ "\n" +s9+ "\n" +s10+ "\n" +s11+ "\n" +s12+ "\n" +s13+ "\n" +s14+ "\n" +s15+ "\n" +s16+ "\n" +s17+ "\n" +s18+ "\n" +s19+ "\n" + s20;
The line breaks happened because of some empty fields.
Thank you
Add this at the end of your code:
event.value = event.value.replace(/\n+/g, "\n");
You will need a different kind of script to do all of that. Basically, you need to check the value of each field, before adding it to the final string. So something like this:
var s = "";
var lineCounter = 0;
var s1 = getField("Hob.1").valueAsString;
if (s1) {
lineCounter++;
s+=lineCounter+". Local Website ($"+s1+"/mo)\n";
}
var s2 = getField("Hob.2").valueAsString;
if (s2) {
lineCounter++;
s+=lineCounter+". National Website ($"+s1+"/mo)\n";
}
// etc.
event.value = s;
In Hob.9, for example, use this code:
// Get the field values, as strings
var z1 = getField("qHob.9").valueAsString;
var z2 = getField("Q_Hob_9").valueAsString;
// Combine values, separated by a space, if not empty
if (z1=="" || z2=="") event.value = "";
else event.value = z1 + " " + z2+ "X";
Copy link to clipboard
Copied
Add this at the end of your code:
event.value = event.value.replace(/\n+/g, "\n");
Copy link to clipboard
Copied
Thank you very much, it's working
Could we add another code to number the lines?
for exampel:
1. Local Website ($390/mo)
2. National Website ($495/mo)
3. 10 Products ($690/mo)
4. 100 Products ($750/mo)
Copy link to clipboard
Copied
I found a solution for numbering the list of services, by using this code:
var myVar = 0;
if(event.value != "") {
event.value = event.value.split(/[\n\r]/g).map(function(a){return (myVar = myVar + 1)+") " + a}).join("\n");
}
but I have a problem with the first line
in both cases if I give it a numbeing format or without it, without number it appears as an empty line at the first.
Copy link to clipboard
Copied
You will need a different kind of script to do all of that. Basically, you need to check the value of each field, before adding it to the final string. So something like this:
var s = "";
var lineCounter = 0;
var s1 = getField("Hob.1").valueAsString;
if (s1) {
lineCounter++;
s+=lineCounter+". Local Website ($"+s1+"/mo)\n";
}
var s2 = getField("Hob.2").valueAsString;
if (s2) {
lineCounter++;
s+=lineCounter+". National Website ($"+s1+"/mo)\n";
}
// etc.
event.value = s;
Copy link to clipboard
Copied
Copy link to clipboard
Copied
It's OK to share it, of course, but what's your specified question about it?
Copy link to clipboard
Copied
The same question, I would love to fix the 'Summary of Services' textfield to auto number the list, and remove the prefix line preak before the first line.
I shared to document, to not waste your time, and help me with the required code, I don't have enought knowledge in JavaScripts
Thanks again
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Check-boxes always have a value. When they are not ticked that value is "Off".
So you need to change all of the lines of this type:
if (s1) {
To:
if (s1!="Off") {
Copy link to clipboard
Copied
Sorry, I didn't notice the hidden fields... Disregard the above comment.
Copy link to clipboard
Copied
The issue is with the code of (some of) the hidden fields. For example, under "Hob.16" the code is:
event.value = this.getField("cHob.1").value == "Off" ? "" : "Retargeting ($550/mo)";
It should refer to "cHob.16", I'm presuming, not "cHob.1"...
Review all of these codes and make sure they are correct.
Copy link to clipboard
Copied
It might be a good idea to make those fields visible, so you could see their values and could debug them more easily... Doing so I found out that the two X's come from Hob.9 and Hob.10, where you have scripts that add them, regardless of whether or not the other fields are empty, which results in them always being added to the summary.
Copy link to clipboard
Copied
Actually Yes, it's becase of the scripts related to Hob.9 and Hob.10
Could we add if function somewhere to add the "X" only if the Quantity fields are not empty?
Copy link to clipboard
Copied
Hello,
I hope you are doing well,
I tried hundredws of ways to fix it but I couldn't
I only need to change the code here in Hob.9 and Hob.10, to give me the quantity without adding new fields.
every thing is working well, from Hob.1 to Hob.21, but I need to change the code little bit in Hob.9 and Hob.10 to recognize the quanitity
Take a look at the attached file please, I checked all of the checkboxes, except 9 and 10
Best Regards
Tnanks in advance
Copy link to clipboard
Copied
In Hob.9, for example, use this code:
// Get the field values, as strings
var z1 = getField("qHob.9").valueAsString;
var z2 = getField("Q_Hob_9").valueAsString;
// Combine values, separated by a space, if not empty
if (z1=="" || z2=="") event.value = "";
else event.value = z1 + " " + z2+ "X";
Copy link to clipboard
Copied
Thank you very much
Working 100%
Copy link to clipboard
Copied
Thanks for that, I fixed it