Jump to content

Js: Combining (Concatenating) Fields In Tabular Report


Recommended Posts

I need to combine two (at times more, but once I can resolve for 2 I can easily extend) fields into a third field and commit the value back into the database, all the while working with fields in the results page of a tabular report. 
 
The example on the forum, ( http://forums.caspio.com/index.php/topic/3200-js-concatenatecombine-two-fields-into-one-field/ ) , is good but only for submission forms, and the comments on extending it also apply only to update forms or detailed pages of tabular reports. So basically it can't work within a given row in a table as it stands now. I have also checked out the example in ( ) but this one is about totalling a column across multiple rows, and it anyway doesn't commit the results to the database, whereas I need to combine multiple columns across the same row, AND commit to the database.  
 
Combining the learnings from the above two examples, I have tried as follows but it is not resulting in any value being inserted in the target field, and my suspicion is I need to do something different in the very last statement of the function. Please advise.
 
1. Added an HTML block at the top of the list of fields (so effectively the first column in the tabular report) containing:
 
<div id="row_at_a_time">
 
2. Added an HTML block at the end of the list of fields (so effectively the last column) containing:
 
</div>
<SCRIPT LANGUAGE="JavaScript">
function concatenate() 
{
   var ProcessName = document.getElementById("row_at_a_time").getElementByTagName("Table")[1].getElementByTagName("tr")[1].getElementByTagName("td")[1].innerHTML;
   var ProjectID = document.getElementById("row_at_a_time").getElementByTagName("Table")[1].getElementByTagName("tr")[1].getElementByTagName("td")[6].innerHTML;
   var ChkUnique = ProjectName + ProjectID;
   document.getElementById("row_at_a_time").getElementByTagName("Table")[1].getElementByTagName("tr")[1].getElementByTagName("td")[6].innerHTML = ChkUnique;
}
document.getElementById("caspioform").onsubmit=concatenate;
</script>
 
 
Note that:
 
- The first [1] in each of the statements is something I don't understand but have simply followed the example - what does it refer to?
- The second [1] in in the place where the example uses "row_index" so it should help point to "current row" since we have declared each row of the tabular report as a single-row-table (I believe row indexes start at 1, and not 0, unlike column numbers?)
- The last number in each of the statements ([1], [6] and [7]) points to the column numbers and means I am setting column [7] to be the concatenation of [1] and [6]. This will have to be customised for each use of this method in various tabular reports.
 
However I think I am missing the equivalent of "insert record" aspect of the following statement and just setting the variable doesn't complete the job:
 
document.getElementById("InsertRecordChkUnique").value = ChkUnique;
 
And therefore this method is not working. Any thoughts?
 
Incidentally I am using this method to enforce uniqueness across multiple columns, so for example column A and column B are individual not unique but column B needs to have unique entries for all records for a given value of column A. I am concatenating the two columns and forcing the value into a third column (hidden from users) which is set to "unique" so that the user is stopped from committing such records. If you know of a different way to achieve this which does not need the above solution, that too will solve my original problem anyway. And the key is to make this work in tabular reports, not just submission or update forms. And it needs to fire on insert as well as update. 
 

 

Many thanks! 
Link to comment
Share on other sites

Hello Niranjan,

 

Do you want to modify the third field when a user clicks the "Edit" button, changes values and clicks the "Modify" button?

If yes, could you provide names of fields?

 

I want to find more simple script, and I need some more information to understand what is the exact expected result.

Link to comment
Share on other sites

Yes I want to update the third column with the concatenation of the first two columns, wherever either of the first two get modified in any way, whether insert or edit / update. The column names should not really matter, since I can change that to suit the situation if you can show me a way, but since you ask, the three columns are called ProjectID, ProcessName, and ChkUnique. The value in ChkUnique (which remains hidden) needs to be ProjectID+ProcessName, whenever either ProjectID or ProcessName changes in any way. I will set ChkUnique to be a "unique" field at the database level. That way, for any given ProjectID, the user will be forced to chose ProcessNames which are unique within that Project, but you could have the same ProcessName appear again in another ProjectID. (It is like you can't have the same file name twice in the same folder, but you can have the same file name used again in another folder).

 

Hope this helps, and thanks for looking into it! Really appreciate it. 

 

Best regards

Link to comment
Share on other sites

  • 10 months later...

Any updates to this? I need to have a calculated field pass to another within the tabular report so that the field can then update the table by being a editable field without having to go to the details page and update every record one at a time.

you should make a new thread. Niranjan was concerned with something else.

 

My take on his problem is that he should be doing something else entirely instead of trying to figure that out.

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.

Loading...
×
×
  • Create New...