Create Zendesk Ticket Comment using different AuthorID through APIv2 - zendesk

Using Zendesk API v2, and .NET library by Elizabeth (https://github.com/mozts2005/ZendeskApi_v2), I'm trying to create Ticket Comments with a different authorID, like so:
api.Tickets.UpdateTicket(new Ticket
{
Id = ticketID,
Comment = new Comment
{
AuthorId = zendeskUserID,
Body = comment
},
});
Ticket gets updated, but when I load the Ticket, the author ID of the comment is the ID of the API user, and not the author-ID I set as zendeskUserID.
Can someone please explain how I can accomplish submitting ticket comment as a different author/user? I have even tried the following to see if anything comes out differently, but nothing has worked:
api.Tickets.UpdateTicket(new Ticket
{
SubmitterId = zendeskUserID,
ExternalId = zendeskUserID,
Id = ticketID,
Comment = new Comment
{
AuthorId = zendeskUserID,
Body = comment
},
});
Please note that the zendeskUserID already exists as an External User in Zendesk.
Thanks.

Related

Subscribe to a users My Matters via SDK

Using Autonomy WorkSite 8.5 SP2 SDK, I am attempting to programmicaly add a shortcut to another users My Matters which I have been told can be done by first subscribing to the other users My Matters, add the shortcut then unsubscribe.
I am therefore attempting to subscribe to another users My Matters however I am having issues with how to subscribe, with the below code I am able to locate the user's My Matters:
Dim objSFSP As IManSubscriptionFolderSearchParameters = oDms.CreateSubscriptionFolderSearchParameters
objSFSP.Add( imFolderAttributeID.imFolderOwner, sShortcutUser )
Dim objFolders As IManFolders = oMatters.FindRootSubscriptionFoldersNotSubscribedTo(oDatabaseList, objSFSP)
And from reading the COM Reference guide I should be able to subscribe to a users My Matters with the following code:
Dim objWorkArea As IManWorkArea = oSess.WorkArea
Dim oFolderShortcuts As IManSubscriptionFolderShortcuts = objWorkArea.SubscriptionFolder.SubFolders
Dim oFolderShortcut As IManFolderShortcut = oFolderShortcuts.AddNewSubscriptionFolderShortcutInheriting(objFolders)
The problem I am encountering is AddNewSubscriptionFolderShortcutInheriting() expects an object of the type IManSubScriptionFolder where FindRootSubscriptionFoldersNotSubscribedTo() returns a IManFolders object.
Can anyone point me in the direction of what I need to do to get an instance of the users My Matters as a IManSubscriptionFolder object?
Probably my response will be a bit late for you, but I hope that it will help anybody else who will have the same issue.
Answering your question, in order to get an instance of other users My Matters as a IManSubscriptionFolder object you just need to loop through the collection of objFolders and cast each folder to the IManSubScriptionFolder type.
Please find below my working solution:
ManDMS dms = new ManDMS();
string serverName = "dms.server.com";
IManSession session = dms.Sessions.Add(serverName);
string userID = "user";
string password = "password";
session.Login(userID, password);
ManStrings dblist = new ManStrings();
dblist.Add("TargetWsDbName");
IManSubscriptionFolderSearchParameters searchParams = ndms.CreateSubscriptionFolderSearchParameters();
string folderOwner = "AnotherUser";
searchParams.Add(imFolderAttributeID.imFolderOwner, folderOwner);
IManFolders nonSubscribedRootSubscriptionFolders = session.WorkArea.SubscriptionFolder.FindRootSubscriptionFoldersNotSubscribedTo(dblist, searchParams);
foreach (var folder in nonSubscribedRootSubscriptionFolders)
{
//another user's subscription folder
var subscriptionFolder = folder as IManSubscriptionFolder;
if (subscriptionFolder != null)
{
//Current user's subscription folder shortcuts
var subscriptionFolderShortcuts = session.WorkArea.SubscriptionFolder.SubFolders as IManSubscriptionFolderShortcuts;
if (subscriptionFolderShortcuts != null)
{
subscriptionFolderShortcuts.AddNewSubscriptionFolderShortcutInheriting(subscriptionFolder);
}
}
Please note that code from above was included for reference purpose only and it is not a production code.

quickbooks online API, bill with parent resale number doesn't have value

Referring to the following post: http://ippdocs.intuit.com/0025_QuickBooksAPI/0050_Data_Services/v2/0400_QuickBooks_Online/Customer/Custom_Fields_for_Customer_and_Job
I am specifically looking for accounts in my QBO that have a parent -> child relationship. Howewver, in cases where Bill With Parent is true, there is no value coming in for "Resale Number," which I would assume would be the parent's QBO Id?
Any help clarifying on how to pull this information would be helpful.
In C# I'm doing the following and looping the accounts available:
var qboCustomer = new Intuit.Ipp.Data.Qbo.Customer();
var qboCustomers = commonService.FindAll(qboCustomer, page, custKnt).ToList();
custKnt = qboCustomers.Count;
foreach (var c in qboCustomers)
{
Intuit.Ipp.Data.Qbo.BooleanTypeCustomField parentBilling = (Intuit.Ipp.Data.Qbo.BooleanTypeCustomField)c.CustomField.Where(a => a.DefinitionId == "Bill With Parent").FirstOrDefault();
if (parentBilling != null)
{
if (parentBilling.Value == true)
{
Intuit.Ipp.Data.Qbo.StringTypeCustomField resaleNum = (Intuit.Ipp.Data.Qbo.StringTypeCustomField)c.CustomField.Where(a => a.DefinitionId == "Resale Number").FirstOrDefault();
if (resaleNum != null)
{
//do some stuff, however, resaleNum is ALWAYS null...
}
}
}
Cases where Bill With Parent is true is like creating jobs(sub customers) for customers.
The "Resale Number" should be set in the custom fields or on the UI under tax info as shown.
Then only it is displayed and will not be null. It is not set to the parent's QBO Id.
You code is correct. I verified it. Just set the resaleNum to retrieve it.

Grails: sort order on one-to-many relationship not working

I've got a simple bi-directional one-to-many mapping, as follows, with a default sort order specified on the owning side. However, the sort order doesn't seem to be getting applied? I'm using Grails v2.0.1 (I've now replicated this example with v1.3.7).
package playground
class User {
String name
static hasMany = [ posts : Post ]
static mapping = {
posts sort:'position'
}
}
and
package playground
class Post {
int position = 1
String message
static belongsTo = [ user : User ]
}
this is the integration test code I'm using to exercise it ...
def User user = new User(name:'bob')
user.addToPosts(new Post(position:2, message:'two'))
user.addToPosts(new Post(position:3, message:'three'))
user.addToPosts(new Post(position:1, message:'one'))
assertTrue user.validate()
assertFalse user.hasErrors()
assertNotNull user.save()
for (post in user.posts) {
log.debug "Post message> ${post.message}"
}
Please put me out of my misery, it's presumably something obvious but I can't see it! Thanks.
use this code:
package playground
class User {
String name
static hasMany = [ posts : Post ]
static mapping = {
posts sort:'position' order:'desc'//order:'asc'
}
}
Turns out this is a bit of odd edge-case behaviour, that's really a result of the way the test is written. Basically, everything is happening in the scope of a single Hibernate session/txn (see conversations above). So the test is fetching back the object graph it just created (with the out of order Set), rather than fetching data from the database.
If you force a separate transaction then you get the behaviour you are looking for and the 'order by' works as expected. E.g.
User.withNewSession{ session ->
def User foundUser = User.get(user.id);
for (post in foundUser.posts) {
println "Post message> ${post.message}"
}
}
Code courtesy of ndtreviv.
If you use a list instead of a Set (the default) the framework will maintain the order for you.
List posts = new ArrayList()
static hasMany = [ posts : Post ]
Owens answer got me out of the confusion i was in. i was trying to the the ordering defined on a relationship between users (1) and posts (many), but when i wrote the initial tests they were failing as using User.get (u.id) was in the same session - and so was just reading out of the cache and they came back in the order i'd written tem not newest first as i'd expected.
I then rewrote the test across two sessions and low and behold in the second session this time returned the posts in desc order.
So you just have to be careful. if you are in the same original session that creates the posts then you have to use User.get (u.id).posts.sort().
All these little gotchas with not understanding properly how the session cache and underlying DB work in the scope of the same session/transaction. makes your brain ache sometimes.
whilst we are noting things - this errored in integration test in 3.2.5, but i spotted a thread by Jeff and the fix that had gone. So i upgraded to grails 3.2.6 last night and this test now works
void "test query"() {
given:"a user and where query for users, and posts "
User u
when: "create a post for user "
User.withNewSession { session ->
u = new User(username: 'will')
u.save(flush: true, failOnError: true)
Post p1 = new Post(comment: [food: "bought coffee and cake "])
Post p2 = new Post(comment: [dinner: "bought wine and dinner"])
Post p3 = new Post(comment: [view: "spectacular view of lake and sunset"])
u.addToPosts(p1)
u.addToPosts(p2)
u.addToPosts(p3)
u.save(flush: true)
if (u.hasErrors())
println "error saving posts on user u : ${u.errors}"
def postList = User.get(u.id).posts
postList.each { println "query via user.list using same session > $it.dateCreated : $it.comment" }
Post.findAll().each { println "query via Post using same session > $it.dateCreated : $it.comment" }
}
//because still in same session it just returns the order from the 1st level cache - so force a
//new session and let the DB do the sort
def lookupPosts
User.withNewSession{ session ->
User uNew = User.get(1)
assert uNew
lookupPosts = uNew.posts
lookupPosts.each {println "query via user in new session > $it.dateCreated : $it.comment" }
}
then: " check post was added"
!u.hasErrors ()
lookupPosts.size() == 3
lookupPosts[1].comment.dinner == "bought wine and dinner"
}

Grails/GORM: creating one-to-one optional relationship

I'm designing a system in which posts/discussions between users can be upgraded to become tickets. At one particular place I'm trying to create a one-to-one optional relationship but am running into certain issues. A condensed version of the entities in the spotlight is given below.
Rules:
A Post can become a Ticket if required. (optional)
A Ticket must have a Post. (mandatory)
Post.groovy
class Post {
String title
String description
String postedBy
Ticket ticket
static hasMany = [comments: Comment]
static constraints = {
title(blank:false)
description(blank:false)
postedBy(blank:false)
ticket (nullable:true,unique:true)
}
}
Ticket.groovy
class Ticket {
String title
String description
String postedBy
Post post
static hasMany = [responses: Response]
static constraints = {
title(blank:false)
description(blank:false)
postedBy(blank:false)
post (nullable:false,unique:true)
}
}
This works to some extent. I can:
Create a Post leaving the ticket attribute null If and when the post is upgraded to become a ticket
I can explicitly set the Post's ticket attribute to point to the parent ticket.
However, this mapping isn't enforced at the domain level. It leaves room for a situation where Ticket1 points to Post1, but Post1 points to Ticket2 instead.
I tried using a static hasOne = [post: Post] in the Ticket class but later learned that it mandates the presence of a static belongsTo = [ticket: Ticket] in the Post class and this becomes a mandatory 1-to-1 relationship which is not what I'm looking for.
Is there a way to achieve this 1-to-1 optional mapping in this scenario? Any pointers would be most helpful.
You could consider making a custom validator like
class Post {
// Other fields
Ticket ticket
static constraints = {
// Other constraints
ticket (nullable:true,unique:true, validator: { val, obj ->
if(val) {
return val.post == obj
}
})
}
}
Would this solve your problem?

Grails issue with unique/save/update

I'm having an issue with grails. I have a domain that looks like:
class Book {
static belongsTo = Author
String toString() { title }
Author bookAuthor
String title
String currentPage
static constraints = {
bookAuthor()
title(unique:true)
currentPage()
}
}
The main thing to note is that I have title(unique:true) to avoid from adding the same book twice. However, this is causing issues. In the controller I have created:
def populate = {
def bookInstance = new Book()
def dir = 'C:/currentBooks.txt'
def bookList
bookList = readFile(dir) //read file and push values into bookList
int numOfBooks = bookList.size()
numOfBooks.times {
bookInstance.setBookAuthor(bookList.author[it])
bookInstance.setTitle(bookList.title[it])
bookInstance.setCurrentPage(bookList.title[it])
bookInstance.save()
}
}
I call populate to read a file and populate the database with new Books. The problem is that I want to update it with new values. For instance, lets say that the book already exists in the database but I have read farther into the book and want to change the currentPage so the data is changed in the file and populate is called but doesn't update the page because the title already exists.
Can someone explain how to update the results with the new values?
First of all, you need a key for your Book domain object. You have the title marked as unique, which suggests you want to use that to uniquely identify a Book. I'd recommend against that (what happens when two books have the same title?) and use the id grails provides by default. That means you'll have to store the id in your currentBooks.txt in addition to your other fields.
Once you've got an id, you can try loading an existing record from the database. If not, create a new one. For Example:
def dir = 'C:/currentBooks.txt'
def bookList
bookList = readFile(dir) //read file and push values into bookList
int numOfBooks = bookList.size()
numOfBooks.times {
def bookInstance.get(bookList.id[it])
if (!bookInstance) {
bookInstance = new Book()
}
bookInstance.setBookAuthor(bookList.author[it])
bookInstance.setTitle(bookList.title[it])
bookInstance.setCurrentPage(bookList.title[it])
bookInstance.save()
}
Alternatively, you could use the title as the id. This is a bad idea as indicated above, but it saves having to keep track of a separate id and change the format of currentBooks.txt. With Book defined as below, you could call Book.get(bookList.title[it]):
class Book {
static belongsTo = Author
String toString() { title }
Author bookAuthor
String title
String currentPage
static constraints = {
bookAuthor()
title(unique:true)
currentPage()
}
static mapping = {
id name: 'title', generator: 'assigned'
}
}

Resources