I am planning of writing a plugin on the topic update, and retrieve the list of all the references where a particular topic is being used. Please help me with some guidance.
-
Please refer to the documentation to start with docs.rws.com/796504/787966/sdl-tridion-docs-14-sp2/…– Anand N S ♦Nov 18, 2021 at 7:36
-
I am going through the documents but couldn't find something like "GetUsingItems" or whereused for the Context.– SDLBeginnerNov 18, 2021 at 9:57
1 Answer
You need to be using the Content Manager web services API in Docs to be able to retrieve the references for a topic. The documentation of an example web service call is here.
The web service class you are looking for is the Reports class which contains the method GetReferencesByIshLngRef
. This method is synonymous with Where Used and will return where a specific topic is referenced.
So in your application, you would add a service reference to the Reports service. The URL would be the web service URL followed by /Wcf/API20/reports.svc
and for the namespace give something like ReportsClientServiceReference
. For example, https://docs.sdldemo.com/ISHWS/Wcf/API20/reports.svc
. Visual Studio would then generate the necessary classes and update the .config appropriately. You should be able to now call the method GetReferencesByIshLngRef
.
The following example code should get the list of items referenced by a topic.
var ishWSUri = new Uri(@"https://docs.sdldemo.com/ISHWS/");
var ishWSBinding = new CustomBinding("CustomBinding_Application1");
var reportsUri = new Uri(ishWSUri, "Wcf/API20/Reports.svc");
var issuerUri = new Uri(@"https://docs.sdldemo.com/ISHSTS/issue/wstrust/mixed/username");
var credential = new NetworkCredential("<user name>", "<password>");
var authenticationType = enAuthenticationType.UsernameMixed;
var token = IssueToken(issuerUri, authenticationType, credential, ishWSUri);
var reportsClient = new ReportsClientServiceReference.ReportsClient(ishWSBinding, new EndpointAddress(reportsUri));
var reportsChannel = reportsClient.ChannelFactory.CreateChannelWithIssuedToken(token);
ReportsClientServiceReference.GetReferencesByIshLngRefRequest inValue = new ReportsClientServiceReference.GetReferencesByIshLngRefRequest();
string xmlExtObjectList = "<ishfields>" +
" <ishfield name='VERSION' level='version'/>" +
" <ishfield name='DOC-LANGUAGE' level='lng'/>" +
" <ishfield name='FTITLE' level='logical'/>"
"</ishfields>";
// The ID of the topic at the language level. This can also be a comma-seperated list.
inValue.lngRefs = "11689";
inValue.xmlExtObjectList = xmlExtObjectList;
ReportsClientServiceReference.GetReferencesByIshLngRefResponse references = reports20Channel.GetReferencesByIshLngRef(inValue);
String returnValue = references.returnValue;
// xmlOutput contains all Docs objects referenced by a topic.
String xmlOutput = references.xmlExtObjectList;
-
Thank you Sabarish. Actually I am aware of the content manager web services, but I need to perform this activity on a topic update. So thought plugin will be right way to achieve this requirement. On topic update we need to find the references and need to update the latest version of the topic in there. Please suggest how can we achieve this using Write plugins. Nov 19, 2021 at 4:53
-
Write plugins would not contain any methods to get topic references. In the write plugin handler, you would have to make a call to the CM web services API to get topic references. Or you can create a REST service on top of the CM web service that returns topic references and call that in the handler. Nov 19, 2021 at 5:49
-
Hi Sabarish.. You are correct, there are no such methods present in plugin. We need to use CM web Api to perform that task. I am marking your answer as answer to the question as there is no other go. Thank you. Dec 1, 2021 at 14:05