Coder Social home page Coder Social logo

Comments (35)

yilin4 avatar yilin4 commented on August 10, 2024

@ishanig11 Could you please provide your document and your complete gist? And I found there is some syntax errors in your code. There are some references of word js api as following.
customDocProps.getItemOrNullObject
https://learn.microsoft.com/en-us/javascript/api/word/word.custompropertycollection?view=word-js-preview#word-word-custompropertycollection-getitemornullobject-member(1)
the second parameter of k.result.insertText
https://learn.microsoft.com/en-us/javascript/api/word/word.range?view=word-js-preview#word-word-range-inserttext-member(1)

from office-js.

ishanig11 avatar ishanig11 commented on August 10, 2024

FieldRefresh.docx
I dont see any syntax error in above code. I call this code inside one of function. And this function gets called as ExecuteAction of office manifest command.

from office-js.

yilin4 avatar yilin4 commented on August 10, 2024

@ishanig11 Can you provide your screenshots of the error?
image
I tried to run your code but the code with red underline is not correct. As the link I shared you before, the customDocProps.getItemOrNullObject doesn't have the second parameter and the insertText's second parameter should be one of these(insertLocation: Word.InsertLocation | "Replace" | "Start" | "End" | "Before" | "After")

from office-js.

ishanig11 avatar ishanig11 commented on August 10, 2024

Thanks for pointing this. I changed error line to k.result.text.replace(k.result.text, "New Value")
But this is not replacing field value. I want to update field value which user can do in Ms Word by "Update Field".

from office-js.

yilin4 avatar yilin4 commented on August 10, 2024

@ishanig11 It should be k.result.insert(k.result.text, "Replace"), you can try it. And if there still are questions on this please let me know~ thank you.

from office-js.

ishanig11 avatar ishanig11 commented on August 10, 2024

DemoDocument.docx
image

Refer attached document. Here Hello Word is getting inserted. But you can see field values are not replace.

from office-js.

yilin4 avatar yilin4 commented on August 10, 2024

@ishanig11 Can you describe the scenario that you use field? From the document, I think you just want to replace the title and the major_rev to other string. If so, maybe the content control will be more suitable.

from office-js.

ishanig11 avatar ishanig11 commented on August 10, 2024

Uploading ReactWordPortFolio.zip…
Steps.docx
Refer this document for exact requirement and current issue.
Uploading ReactWordPortFolio.zip…
Project file.

Kindly check and let me know in case of any questions.

from office-js.

ishanig11 avatar ishanig11 commented on August 10, 2024

@yilin4 any update on this issue?

from office-js.

yilin4 avatar yilin4 commented on August 10, 2024

@ishanig11 Sorry for responding late. I have tried the following statement to insertText to a Field, you can have a try. But it's for changing the first Field in a document, and you can modify it according to your need.

const fields = context.document.body.fields; const field = fields.getFirstOrNullObject(); field.result.insertText("123", "Replace");

from office-js.

ishanig11 avatar ishanig11 commented on August 10, 2024

@yilin4 : I tried above approach but still no change in document Quik Parts field value. Refer below screenshot:
image

from office-js.

yilin4 avatar yilin4 commented on August 10, 2024

@ishanig11 Sorry, I have tried it again, and found it just works in desktop. It has been put on our backlog<Bug#8727789> for internal track. We will keep track of this issue and let you know if there are any updates.

from office-js.

ishanig11 avatar ishanig11 commented on August 10, 2024

@yilin4 : We are completely blocked due to this issue? Can you please talk with developer and find some workaround for now? This is blocker issue for us.

Thanks in advance.

from office-js.

ishanig11 avatar ishanig11 commented on August 10, 2024

@yilin4 : I tried above approach but it did not work in Desktop version also. And I got below error:
image

from office-js.

ishanig11 avatar ishanig11 commented on August 10, 2024

@yilin4 : any update? As mentioned earlier, please provide some workaround as mentioned earlier. As this is blocker issue for us.
Please take it on high priority.

Thanks in advance

from office-js.

ishanig11 avatar ishanig11 commented on August 10, 2024

Any update?

from office-js.

yilin4 avatar yilin4 commented on August 10, 2024

@ishanig11 Sorry to respond late. It can work on desktop, but the field's type can't be others. You can try to set the field type to addin and have a try again.
About the online version, can using ContentControl meet your needs?
Inserting a ContentControl with tag in the selection range.
const selection = context.document.getSelection(); const cc = selection.insertContentControl(); cc.tag = "revision";
Getting the ContentControl with tag and changing its content.
const ccs = context.document.body.contentControls; const target = ccs.getByTag("revision"); target.getFirstOrNullObject().insertText("123", "Replace");

from office-js.

ishanig11 avatar ishanig11 commented on August 10, 2024

We cant't use ContentControl in our document as we have older documents which are using Quik Parts. So need solution for Quik Parts refresh.

from office-js.

yilin4 avatar yilin4 commented on August 10, 2024

@ishanig11 Now, the online Field Object can't support the function you need. Could you estimate the user base and the revenue from your new add-in? So, we can better escalate this case and priories it.
And the current supported field type of online Word and desktop Word is like following:
image

from office-js.

ishanig11 avatar ishanig11 commented on August 10, 2024

@yilin4 : we have developed this feature and now will showcase these to our clients. As per our current surveys client will be interested in this feature. But right now I cant comment on user base and revenue. But definitely it will be good one.

Can you atleast tell me workaround to automatically refresh DOCPROPERTY field types in Desktop version for now?

from office-js.

yilin4 avatar yilin4 commented on August 10, 2024

@ishanig11 Can you tell me the specific field type that in your document that you want to refresh?

from office-js.

ishanig11 avatar ishanig11 commented on August 10, 2024

from office-js.

ishanig11 avatar ishanig11 commented on August 10, 2024

image: refer this image.
I want to refresh docproperty fields. These are fields basically from info->custom properties tab of word document.

from office-js.

yilin4 avatar yilin4 commented on August 10, 2024

@ishanig11 You can try this. It can work on desktop to refresh the docProperty field.
var fields = context.document.body.fields.load("items"); fields.load(["items"]); await context.sync(); for(let i = 0; i < fields.items.length; i++){ const field = fields.items[i]; field.load(); await context.sync(); if (field.type === Word.FieldType.docProperty){ field.result.insertText("test", "Replace"); } }

from office-js.

ishanig11 avatar ishanig11 commented on August 10, 2024

With this field is not updated. See below image:
image

from office-js.

yilin4 avatar yilin4 commented on August 10, 2024

@ishanig11 I record this, you can see it. It's the desktop version.

Recording.2024-02-23.194129.mp4

from office-js.

ishanig11 avatar ishanig11 commented on August 10, 2024

It worked for desktop. Thank you.

But need solution for online version also :) If you can provide some workaround for the same that would be really helpful.

from office-js.

yilin4 avatar yilin4 commented on August 10, 2024

@ishanig11 Now, the online version only has 4 field type, so if your document has the docProperty field, the online Word can't recognize it. If you have this need, we would like to suggest you go to https://techcommunity.microsoft.com/t5/microsoft-365-developer-platform/idb-p/Microsoft365DeveloperPlatform to ask a new question. Feature requests on it are considered when we go through our planning process.

from office-js.

ishanig11 avatar ishanig11 commented on August 10, 2024

const ccs = context.document.body.contentControls; const target = ccs.getByTag("revision"); target.getFirstOrNullObject().insertText("123", "Replace");

If content control is marked as contents can not be edited then through program we can
t update value. I want to make these fields as read only for users so that they can't modify but should be able to update values programaically.
image

from office-js.

yilin4 avatar yilin4 commented on August 10, 2024

@ishanig11 There are two properties in the content control named cannotEdit and cannotDelete, I think you can use these two properties to control the content control not to be edited or deleted by users.

from office-js.

microsoft-github-policy-service avatar microsoft-github-policy-service commented on August 10, 2024

This issue has been automatically marked as stale because it is marked as needing author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. Thank you for your interest in Office Add-ins!

from office-js.

microsoft-github-policy-service avatar microsoft-github-policy-service commented on August 10, 2024

This issue has been automatically marked as stale because it is marked as needing author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. Thank you for your interest in Office Add-ins!

from office-js.

microsoft-github-policy-service avatar microsoft-github-policy-service commented on August 10, 2024

This issue has been automatically marked as stale because it is marked as needing author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. Thank you for your interest in Office Add-ins!

from office-js.

microsoft-github-policy-service avatar microsoft-github-policy-service commented on August 10, 2024

This issue has been closed due to inactivity. Please comment if you still need assistance and we'll re-open the issue.

from office-js.

microsoft-github-policy-service avatar microsoft-github-policy-service commented on August 10, 2024

This issue has been closed due to inactivity. Please comment if you still need assistance and we'll re-open the issue.

from office-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.