Comments (35)
@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.
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.
@ishanig11 Can you provide your screenshots of the error?
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.
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.
@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.
Refer attached document. Here Hello Word is getting inserted. But you can see field values are not replace.
from office-js.
@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.
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.
@yilin4 any update on this issue?
from office-js.
@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.
@yilin4 : I tried above approach but still no change in document Quik Parts field value. Refer below screenshot:
from office-js.
@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.
@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.
@yilin4 : I tried above approach but it did not work in Desktop version also. And I got below error:
from office-js.
@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.
Any update?
from office-js.
@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.
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.
@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:
from office-js.
@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.
@ishanig11 Can you tell me the specific field type that in your document that you want to refresh?
from office-js.
from office-js.
: refer this image.
I want to refresh docproperty fields. These are fields basically from info->custom properties tab of word document.
from office-js.
@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.
With this field is not updated. See below image:
from office-js.
@ishanig11 I record this, you can see it. It's the desktop version.
Recording.2024-02-23.194129.mp4
from office-js.
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.
@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.
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.
from office-js.
@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.
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.
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.
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.
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.
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)
- body.clear() not working for content controls HOT 3
- How to make slide active Or How to insert image using index HOT 4
- Addin sample not showing in new look outlook and browsers. HOT 5
- Identifying Usage of New Outlook in Office-js Add-ins HOT 1
- Not able to sideload outlook addin. in macbook there is no option to add the manifest file HOT 5
- Inserting Signature with the OnMessageSend event duplicates the signature
- The identity API is not supported for this add-in in online Word HOT 2
- Excel Online: calculation state can get stuck in Pending state when workbook contains charts HOT 3
- IP Address Range Needed for Microsoft Office Add-in Validation Process
- Office API messageParent Outlook on android doesn't work
- NAA: Unable to acquire access token for event-based activation (onMessageSend) HOT 2
- Outlook addin using Bootstrap modal or offcanvas bleeds through on Mac version of Outlook. Classic and New Outlook for Mac. HOT 2
- [Word API] Document.compare: ability to specify Original and Revised document?
- Outlook NAA issue: "Something went wrong. [7q6cl]" Error HOT 5
- Web Outlook provides improper attachment data if attachment is still uploading to the email HOT 2
- [Question] Is it safe to use `CustomFunctions.delayinitialization()`
- New Outlook - emails stuck in outlook at queued or draft status HOT 3
- context.application.createDocument works only first time HOT 1
- WorkBook level Define name is getting corrupted while reopening excel using base64
- In Outlook, getAllInternetHeadersAsync works on an item in the Inbox, but not the sent folder
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from office-js.