reference data in preSubmit
reference data in preSubmit

given the ajax return like this:
DT_RowId: "row_1508"
Submissions: {SubmissionStatusID: 2, AssignedToUserID: 2, SubmissionTypeID: 0, QuestionCategoryID: 0,…}
SubmissionStatus: {SubmissionStatus: "Assigned"}
SubmissionTypes: {SubmissionType: null}
QuestionCategories: {QuestionCategory: null}
ResolutionMethods: {ResolutionMethod: null}
AssignedTo: {UserName: "montoyam"}
CCAssignedTo: {UserName: null}
how do I reference a data element in presubmit?
SubmissionsEditor.on('preSubmit', function (e, data, action) {
alert(data.Data.QuestionCategories.QuestionCategory);
//return false;
});
This discussion has been closed.
Replies
Please use your debugger and check the contents of "data". That is the simplest way to find out.
In this example I change the action to be submitted from "edit" to "create" for a special reason ...
But that is not going to work for your submitted field values. They should be in an array like d.data[0].yourField if you are using single edit.
this worked in the browser console, but not in javascript:
data.data[0].QuestionCategories.QuestionCategory
Mmhhh... don't know. You might have a different problem. This works fine for me:
Sorry, I got confused when renaming my original data table names ... you'll figure it out ...
ah, I am not looking at selected row. I thought that was just for the datatable, I didn't know it was needed for the editor. I will give it a try
ok, so it works when I use the datatable. however, that of course would not have the data that is about to be submited. When I change line 2 to pull from selected editor row it doesn't work. I'm guessing line 2 needs to change??
Instead of
SubmissionsEditor
, which is your Editor instance, you need to use the variable assigned to your Datatable instance.Kevin
but this is on presubmit. the data doesn't live in the datatable instance yet (at least it doesn't appear to be).
In line 1 of my posted code there is a variable in the function 'data'
doesn't that contain the data without having to grab a selected row? if it does, how do I reference it given the structure of my json?
Well, maybe the getting the selected row is not what you want. I was just following rf1234 answer. Yes, according to the
preSubmit
docs thedata
parameter is:Ho do you access it? Its hard to say without understanding your data structure, ie, the
columns
config. What is the output of this?Kevin
I hope I didn't confuse you guys. It is almost 2 am here ... and I had a little celebration by myself: I rolled out a big piece of software today! ... my favorite bar is closed .. my wife's sleeping ... youTube ... a couple of beers ... not a real life isn't it? I hope Covid-19 will disappear soon!!
Congrats on the software release! All bars are closed here too, everyone at home, so all very odd!
ok, so I was looking at the json return of the api, not realizing that the editor does have all the left joined tables. my first mistake
But, I still am not sure how to access the editor data. I see a row number in the console dump, which of course would change for each row.
this works, but the row number is hard coded, which of course won't work
See if
data.QuestionCategoryID
works. Did you try adding the console.log statement I suggested? That should show you exactly what you need to use.Kevin
yes, the console log results were posted above. data.QuestionCategoryID didn't work.
here is the console log in the exact format:
so this seems to work. not sure if it is the best way...
Hi montoyam,
from the console log above I guess I understand what your challenge is: How do you get the content not knowing what the rowId of the row is that you are actually dealing with. If that isn't your challenge forget all of the following please
The records I edit or create have this structure. (The row_id would be 0 for "create").

Now I had the requirement to manipulate this stuff before it gets send to the server. This is what I did to handle both "edit" and "create":
If I look at this:
This should also work (in your case it should be "data.data" instead of "d.data"):
that looks like it does basically the same as the code I posted. but thanks.
actually, I stumbled upon an even easier way: