Can you please let us know if it is possible retrieve user ID of the person who last modified a document using MOSS list web service? If yes, please let me know the column name.
Each item has a Modified property, as well as a Modified By field, which respectively have Modified and Editor as their Internal field names. SO yes you can view who modified a document last and when that modification was done.
The CAML for the ViewFields would be
<ViewFields>
<FieldRef Name='Modified' />
<FieldRef Name='Editor' />
</ViewFields>
So placing this in the MSDN example on the GetListItems documentation page woulbe become:
SrvRef.Lists listService = new Web_Reference_Folder.Lists();
listService.Credentials= System.Net.CredentialCache.DefaultCredentials;
XmlDocument xmlDoc = new System.Xml.XmlDocument();
XmlNode ndViewFields = xmlDoc.CreateNode(XmlNodeType.Element,"ViewFields","");
ndViewFields.InnerXml = "<FieldRef Name='Modified' /><FieldRef Name='Editor' />";
// maybe add a Where clause as well to retrieve specific items only
// XmlNode ndQuery = xmlDoc.CreateNode(XmlNodeType.Element,"Query","");
// ndQuery.InnerXml = "<Where><ADD PREDICATES HERE</Where>";
try
{
XmlNode ndListItems = listService.GetListItems("LISTNAME", null, null, ndViewFields, null, null, null);
// do something with the result
}
catch (System.Web.Services.Protocols.SoapException ex)
{
MessageBox.Show("Message:\n" + ex.Message + "\nDetail:\n" + ex.Detail.InnerText + "\nStackTrace:\n" + ex.StackTrace);
}
Related
I am trying to select a field from another CRM entity by using an expand with my odata query.
Query string: studios$?Select=studioid,studioname,titleid&$Expand=
Title id is a field in custom entity called title. How do I write an expand clause to expand title and select titleid?
Any help is appreciated!
first you can refer to this article from docs.microsoft explaining in detail the $expand feature, however for simplicity is followed by the relation name with targeted entity then the fields you want to select in parentheses
for ex. $expand={relation_name}($select=filed1,field2)
which might be something like this
$expand=new_new_entity1_new_entity2($select=new_name,createdon)
Notice: the values you get from expand relation will be actually navigation URL to actual data, so you don't expect [new_name,createdon] from new_entity2 to be retrieved, what you will get will be a url to OData those values and for that you might below helping function 1 will do it for you
Also you can use XRM Rest Builder that's an amazing solution when you install on the crm you will find it's button in solutions view. that solution is a tool helps you to design your OData query with nice GUI so that you don't need to write and refine your OData query which is faster and easier.
Helping function 1
`
function OdataExpand(expandUrl) {
var result = null;
var req = new XMLHttpRequest();
req.open("GET", expandUrl, false);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var results = JSON.parse(this.response);
result = results;
} else {
console.log("OdataExpand Error : ");
console.log(this);
}
}
};
req.send();
return result;
}
`
but if you want to get all the data with one call and maybe you want to expand to more than one entity i recommend that you use Fetch XML simply design the fetch you need using advanced find tool to extract the fetchXML then pass it to Helping Function 2 that should return the full data but be aware that max fetch length in this approach is limited to 2,048 characters [Max Length for GET Request].
Helping Function 2
`
function ExecuteFetchXMLQuery(dataSet, fetchQuery) {
var encodedFetchXML = encodeURIComponent(fetchQuery);
var result;
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.0/" + dataSet + "?fetchXml=" + encodedFetchXML, false);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Prefer", "odata.include-annotations=\"OData.Community.Display.V1.FormattedValue\"");
req.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200 || (this.status >= 200 && this.status <= 206)) {
console.log("Success Executing Fetch");
var results = JSON.parse(this.response);
result = results;
}
else {
console.log("Error Executing Fetch");
console.log(this);
console.log(this.statusText);
}
}
};
req.send();
return result;}
`
Try this:
studios?$select=studioid,studioname,titleid&$expand=titleid($select=titleid,name)
Also it’s recommended to use CRM REST Builder to compose & test CRM web api queries.
Read more
Note: Check your entity & field names, they should look like new_studio & new_studioid
I got an SAPUI5-application in which I create entries and save them via OData-service. That works, the code for the create operation can be found below. What I have to do now is, I need the ID of the inserted record in HANA back in my application. So what I did I implemented a success handler and thought I would get back this ID in the response from my OData-service. But that is not the case, I get back the same value I provided, in this case 0 since this just a dummy value for the OData-service. I did some research on how to tackle this problem, but none of the approaches worked. So I hope someone of you can help me out or got a hint how to do this. Below the code for create-operation, odata-service and the create.xsjs:
Create-operation in SAPUI5:
this.getOwnerComponent().getModel("Mitarbeiter").create("/ARB", oEntry, {
success: function(oData, response){
console.log(response);
}
});
OData-service:
service {
"MITARBEITERABTEILUNG"."ABTEILUNG" as "ABT" navigates ("Mitarbeiter" as "ARB");
"MITARBEITERABTEILUNG"."Mitarbeiter" as "ARB" create using "public.MitarbeiterAbteilung:mitarbeiterMethods.xsjslib::mitarbeiterCreate";
association "Mitarbeiter"
principal "ABT"("ID")
multiplicity "1"
dependent "ARB"("Abteilung")
multiplicity "*";
}
Create.xsjs:
function mitarbeiterCreate(param) {
let aAfterTableName = param.afterTableName;
var oEntry = {};
try {
var statement = param.connection.prepareStatement("SELECT * FROM\"" + aAfterTableName + "\"");
var rs = statement.executeQuery();
var statement2 = param.connection.prepareStatement('SELECT "MITARBEITERABTEILUNG"."MASEQUENCE".NEXTVAL from dummy');
var rs2 = statement2.executeQuery();
while (rs2.next()) {
oEntry.ID = rs2.getInteger(1);
}
statement2.close();
while (rs.next()) {
oEntry.Name = rs.getString(2);
oEntry.Adresse = rs.getString(3);
oEntry.bz = rs.getString(4);
oEntry.Abteilung = rs.getInteger(5);
}
statement = param.connection.prepareStatement('INSERT INTO "MITARBEITERABTEILUNG"."Mitarbeiter" VALUES (?,?,?,?,?)');
statement.setInteger(1, oEntry.ID);
statement.setString(2, oEntry.Name);
statement.setString(3, oEntry.Adresse);
statement.setString(4, oEntry.bz);
statement.setInteger(5, oEntry.Abteilung);
statement.execute();
statement.close();
} catch (e) {
statement.close();
}
}
Answered in the SAP Community here: https://answers.sap.com/questions/566957/how-to-get-the-id-of-an-inserted-record-in-hana-ba.html
The only thing you need to do, is to update the ID value in the "afterTableName" table provided by the function parameter. Something like that:
let statement = param.connection.prepareStatement('update "' + param.afterTableName + '" set ID = ' + oEntry.ID);
statement.executeUpdate();
Of course that needs to be done after you have determined your new ID. In case your column name is not "ID", please replace it with the real column name.
I need a fast way to get a list of links filtered by the link comment.
Have a code:
var linkCommentFilter = "Some link comment";
const string queryString = #"SELECT [System.Id]
FROM workItemlinks
WHERE [System.Links.LinkType] = 'Tested By'
AND [System.Links.Comment] = '{0}'
AND ([Source].[System.Id] IN ({1}))";
var query = new Query(store, string.Format(queryString,
linkCommentFilter,
string.Join(",", wiIds)));
var result = query.RunLinkQuery().ToArray();
When trying to run this code an exception occurred "field System.Links.Comment doesn't exist". How could I fix it?
You can't query Work Item links with specified comment using WIQL as there is no System.Links.Comment field in TFS.
You need to use TFS rest api to get a list of work items with links and attachments, check the sample code below:
public List<WorkItem> GetWorkItemsWithLinksAndAttachments()
{
int[] workitemIds = new int[] { 1, 5, 6, 10, 22, 50 };
VssConnection connection = Context.Connection;
WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient<WorkItemTrackingHttpClient>();
List<WorkItem> workitems = workItemTrackingClient.GetWorkItemsAsync(workitemIds, expand: WorkItemExpand.Links | WorkItemExpand.Relations).Result;
foreach(var workitem in workitems)
{
Console.WriteLine("Work item {0}", workitem.Id);
foreach (var relation in workitem.Relations)
{
Console.WriteLine(" {0} {1}", relation.Rel, relation.Url);
}
}
Then find the specified comment with relation.Attributes["comment"] in workitem.Relations.
I'm trying to retrieve TextAd (Headline,Desc1,Desc2,Display URL and Destination URL) and i failed.
This is my Code on retrieving Text ad it returns Null result
TextAd text = new TextAd();
System.out.println("Headline:"+text.getHeadline());
Syso... etc.
I want to retrieve All details of TextAd , I'm using java.
This is my the code for adding TextAd
public static void runExample(
AdWordsServices adWordsServices, AdWordsSession session, long adGroupId) throws Exception {
// Get the AdGroupAdService.
AdGroupAdServiceInterface adGroupAdService =
adWordsServices.get(session, AdGroupAdServiceInterface.class);
// Create text ads.
TextAd textAd1 = new TextAd();
textAd1.setHeadline("Luxury Cruise to Mars");
textAd1.setDescription1("Visit the Red Planet in style.");
textAd1.setDescription2("Low-gravity fun for everyone!");
textAd1.setDisplayUrl("www.example.com");
textAd1.setFinalUrls(new String[] {"http://www.example.com/1"});
TextAd textAd2 = new TextAd();
textAd2.setHeadline("Luxury Cruise to Mars");
textAd2.setDescription1("Enjoy your stay at Red Planet.");
textAd2.setDescription2("Buy your tickets now!");
textAd2.setDisplayUrl("www.example.com");
textAd2.setFinalUrls(new String[] {"http://www.example.com/2"});
// Create ad group ad.
AdGroupAd textAdGroupAd1 = new AdGroupAd();
textAdGroupAd1.setAdGroupId(adGroupId);
textAdGroupAd1.setAd(textAd1);
// You can optionally provide these field(s).
textAdGroupAd1.setStatus(AdGroupAdStatus.PAUSED);
AdGroupAd textAdGroupAd2 = new AdGroupAd();
textAdGroupAd2.setAdGroupId(adGroupId);
textAdGroupAd2.setAd(textAd2);
// Create operations.
AdGroupAdOperation textAdGroupAdOperation1 = new AdGroupAdOperation();
textAdGroupAdOperation1.setOperand(textAdGroupAd1);
textAdGroupAdOperation1.setOperator(Operator.ADD);
AdGroupAdOperation textAdGroupAdOperation2 = new AdGroupAdOperation();
textAdGroupAdOperation2.setOperand(textAdGroupAd2);
textAdGroupAdOperation2.setOperator(Operator.ADD);
AdGroupAdOperation[] operations =
new AdGroupAdOperation[] {textAdGroupAdOperation1, textAdGroupAdOperation2};
// Add ads.
AdGroupAdReturnValue result = adGroupAdService.mutate(operations);
// Display ads.
for (AdGroupAd adGroupAdResult : result.getValue()) {
System.out.println("Ad with id \"" + adGroupAdResult.getAd().getId() + "\"" + " and type \""
+ adGroupAdResult.getAd().getAdType() + "\" was added.");
}
}
How can i retrieve Those values from adwords.
this is my selector for retrieving the data from adword
SelectorBuilder builder = new SelectorBuilder();
Selector selector = builder
.fields(AdGroupAdField.Id, AdGroupAdField.AdGroupId, AdGroupAdField.Status,
AdGroupAdField.Description1,AdGroupAdField.Description2,AdGroupAdField.Headline)
.orderAscBy(AdGroupAdField.Id)
.offset(offset)
.limit(PAGE_SIZE)
.equals(AdGroupAdField.AdGroupId, adGroupId.toString())
.in(AdGroupAdField.Status, "ENABLED", "PAUSED", "DISABLED")
.equals("AdType", "TEXT_AD")
.build();
Typecast adGroupAd.getAd() to TextAd then you can get headline and other methods.
TextAd textAd = (TextAd)adGroupAd.getAd();
textAd.getHeadline();
I am using the JIRA plugins sdk to work on changed Issues.
I´ve implemented an IssueListener and I have access to the Issue itself and the IssueEvent.
How do I find out which property (summary, description, estimation ...) of my Issue has been changed ?
The changelog is likely to contain what's been changed and there is a method on the IssueEvent object to get this (getChangeLog) and it returns a GenericValue object.
This post on the Atlassian Answers site gives some code related to an Atlassian tutorial on how to write JIRA Event Listeners.
The relevant code snippet is shown below:
if (eventTypeId.equals(EventType.ISSUE_UPDATED_ID)) {
List<GenericValue> changeItems = null;
try {
GenericValue changeLog = issueEvent.getChangeLog();
changeItems = changeLog.internalDelegator.findByAnd("ChangeItem", EasyMap.build("group",changeLog.get("id")));
} catch (GenericEntityException e){
System.out.println(e.getMessage());
}
log.info("number of changes: {}",changeItems.size());
for (Iterator<GenericValue> iterator = changeItems.iterator(); iterator.hasNext();){
GenericValue changetemp = (GenericValue) iterator.next();
String field = changetemp.getString("field");
String oldstring = changetemp.getString("oldstring");
String newstring = changetemp.getString("newstring");
StringBuilder fullstring = new StringBuilder();
fullstring.append("Issue ");
fullstring.append(issue.getKey());
fullstring.append(" field ");
fullstring.append(field);
fullstring.append(" has been updated from ");
fullstring.append(oldstring);
fullstring.append(" to ");
fullstring.append(newstring);
log.info("changes {}", fullstring.toString());
/* Do something here if a particular field you are
looking for has being changed.
*/
if(field == "Component") changeAssignee(changetemp, issue, user);
}
}