BuildingBlock with such Name does not exist in the document glossary

I am getting follwing error on executing the code belove

Error: BuildingBlock with such Name does not exist in the document glossary

			for(StructuredDocumentTag contentControl:contentControlCollection )
			{
				
					String contentControlValue = "value";
						contentControl.setPlaceholderName(contentControlValue);
			}

Can you please help on this

I am trying to set value for content control

@Karthik_M,

Have you tried the latest version of Aspose.Words for Java i.e. 19.6 on your end?

In case the problem still remains, please ZIP and upload your input Word document (you are getting this problem with) here for testing. We will then investigate the issue on our end and provide you more information.

@awais.hafeez
I have attached documentContentControl.zip (13.5 KB)

@Karthik_M,

We tested the scenario and have managed to reproduce the same problem on our end. For the sake of correction, we have logged this problem in our issue tracking system. The ID of this issue is WORDSNET-18735. We will further look into the details of this problem and will keep you updated on the status of correction. We apologize for your inconvenience.

@Karthik_M,

It is to update you that we have completed the analysis of WORDSNET-18735 and it turned out to be an expected behavior. BuildingBlock with the name you set has to be present in the Document.GlossaryDocument otherwise InvalidOperationException will occur. Please read the summary for PlaceholderName property. So, we will close this issue as ‘Not a Bug’.

@awais.hafeez

Thank you for your guidance.

Can you let me know how can i overwrite existing text on content control field using java.

@Karthik_M,

You can build logic on the following code to get the desired output:

Document doc = new Document("E:\\temp\\in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);

StructuredDocumentTag sdt = (StructuredDocumentTag) doc.getChildNodes(NodeType.STRUCTURED_DOCUMENT_TAG,
                                                                true).get(0);
if (sdt.getSdtType() == SdtType.RICH_TEXT) {
    sdt.removeAllChildren();
    sdt.isShowingPlaceholderText(false);

    Paragraph para = new Paragraph(doc);
    sdt.appendChild(para);

    builder.moveTo(sdt);
    builder.getFont().setStyleIdentifier(StyleIdentifier.HYPERLINK);
    builder.insertHyperlink("aspose.com", "https://www.aspose.com/", false);
}

doc.save("E:\\temp\\awjava-19.6.docx");