Related Documents : update file custom field

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
ibarrandres
Posts: 23
Joined: Wed May 27, 2015

01 Apr 2019

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;
});


User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

02 Apr 2019

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
Cheers

ibarrandres
Posts: 23
Joined: Wed May 27, 2015

02 Apr 2019

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.
Attachments
2019-04-02_7-47-19.png
2019-04-02_7-47-19.png (102.05 KiB) Viewed 2590 times

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

02 Apr 2019

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.
Cheers

ibarrandres
Posts: 23
Joined: Wed May 27, 2015

02 Apr 2019

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.

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

02 Apr 2019

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
MultipleItems.png (15.94 KiB) Viewed 2585 times
Are there any JS errors in the console? What version of SharePoint and Forms Designer are you running?
VersionNumber.png
VersionNumber.png (2.97 KiB) Viewed 2585 times
Cheers

ibarrandres
Posts: 23
Joined: Wed May 27, 2015

02 Apr 2019

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
Related Items Saving issue.png (165.39 KiB) Viewed 2584 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.
Last edited by ibarrandres on 02 Apr 2019, edited 1 time in total.

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

02 Apr 2019

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.
Cheers

ibarrandres
Posts: 23
Joined: Wed May 27, 2015

02 Apr 2019

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? :)

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

02 Apr 2019

You could send it to our office, we wouldn't mind :D 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 :P )
Cheers

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 7 guests