Page 1 of 1
Related Documents : update file custom field
Posted: 01 Apr 2019
by ibarrandres
Hello,
I would like to know if there is a way to update custom fields by using the Title input field as a dynamic value?
I am trying to use the Title form field value to update the file "Opportunity" field so that I can later use it as a filter value on my edit and display view. I saw this
https://spform.com/javascript-framework ... ctionality but it doesn't talk about updating other fields besides the name(renaming).
Is there a a way I can do something like this?
Code: Select all
var Title = fd.field("Title").value(); //get form input value
fd.updateDroppedDocuments($('.related-docs'), function(listItem) {
var result = $.Deferred();
var ctx = listItem.get_context();
var file = listItem.get_file();
ctx.load(file);
ctx.executeQueryAsync(function() {
listItem.Set_File("Opportunity", Title) //update file custom Opportunity field.
ctx.executeQueryAsync(function() {
result.resolve();
});
});
return result;
});
Re: Related Documents : update file custom field
Posted: 02 Apr 2019
by Nikita Kurguzov
Dear ibarrandres,
Do you simply want to use Title field to update Opportunity field? This should be quite simple, you could try something like this:
Code: Select all
fd.updateDroppedDocuments($('.related-docs'), function(listItem) {
var title = fd.field("Title").value();
//set the values on uploaded document:
listItem.set_item("Opportunity", title);
listItem.update();
});
Similar examples are given in the article -
https://spform.com/javascript-framework ... ctionality
Re: Related Documents : update file custom field
Posted: 02 Apr 2019
by ibarrandres
Hello,
Thanks for the help. I am actually trying to update the Opportunity field of the document library. My SP Form was created on a custom list and I added a related document pointing to my document library. I was able to get this working by posting via REST api then grabbing the last item ID of the document library and then updating the field with that ID via rest again. I was just thinking if there was something already built in with the js framework.
I attached an image, hopefully this helps explain better.
Thank you.
Re: Related Documents : update file custom field
Posted: 02 Apr 2019
by Nikita Kurguzov
Dear ibarrandres,
This is exactly what the code does. You need to give Related Items CSS class: related-docs and use the code given above.
Re: Related Documents : update file custom field
Posted: 02 Apr 2019
by ibarrandres
oh nice. Thanks for the quick reply.
I got it working but it seems it only works per single uploaded document. If you drag and drop multiple documents at once it only updates the opportunity field on one of the files.
Re: Related Documents : update file custom field
Posted: 02 Apr 2019
by Nikita Kurguzov
Dear ibarrandres,
That's strange, are you sure that this is the case? I've just tested the code and all items are populated at once:
- MultipleItems.png (15.94 KiB) Viewed 2584 times
Are there any JS errors in the console? What version of SharePoint and Forms Designer are you running?
- VersionNumber.png (2.97 KiB) Viewed 2584 times
Re: Related Documents : update file custom field
Posted: 02 Apr 2019
by ibarrandres
Hello,
I am on Version: 3.1.4. I noticed that sometimes it would update 2/3 documents. But never got it to update 3/3.
These are the two console errors that come up individually:
Uncaught updateDroppedDocuments failed: The file OportunitiesDocLib/1 .docx has been modified by i:0#.w|nb\User.Account on 02 Apr 2019 10:10:52 -0500.
undefined
plumsail.fd.core.js?rev=MpJY7TCL01a%2BwEFrs30OLg%3D%3DTAG0:1 Uncaught updateDroppedDocuments failed: Version conflict.
undefined
- Related Items Saving issue.png (165.39 KiB) Viewed 2583 times
When I saw that error I thought maybe I need to turn off versioning on the document library and I did that but still getting the errors.
Re: Related Documents : update file custom field
Posted: 02 Apr 2019
by Nikita Kurguzov
Dear ibarrandres,
The errors are likely to appear if something else is modifying the items, such as workflow. There could be a conflict, and only one change will save.
Re: Related Documents : update file custom field
Posted: 02 Apr 2019
by ibarrandres
aaahh... I forgot I had a workflow running on that. That did it. Thanks a lot! Where should I send a 6 pack of beer?
Re: Related Documents : update file custom field
Posted: 02 Apr 2019
by Nikita Kurguzov
You could send it to
our office, we wouldn't mind
But overall, if you enjoy using our products and they help you achieve results you are looking for, we'll be happy and continue improving, offering new solutions, features and great support (at least try to
)