SBX - Search With Button

SBX - Forum Post Title

Ajax call gives Bad Request Error

Microsoft Dynamics CRM Forum

Albert_ asked a question on 14 Jul 2018 4:32 AM
My Badges

Question Status

Suggested Answer

Hi there all

Im gonna try to change the state and statusreason.
I saw a link and find that useful.

But when I use that It gives me Bad Request Error.
How can I solve this?
Im doing it in salesorder entity and wanna change state value to 3( canceled) and statusreason to 4, so call that in this way :

var recordGuid = Xrm.Page.data.entity.getId();

setRecordStatus ("salesorder", recordGuid ,"3", "100001");


Where I am doing wrong?


Edit : No It gives me http 500 status code :
And here is the fiddler  :
Reply
Radu Chiribelea responded on 14 Jul 2018 4:50 PM
My Badges

Hi Albert,

Is 100001 a custom status reason that you created for your Organization?

I'd get a Fiddler + a CRM Platform trace (if On Premise) and try to get more details on the exception.

Hope this helps,

Radu

Reply
Albert_ responded on 15 Jul 2018 12:03 AM
My Badges

Hi there sir, I changed the request string and now it gives me 500 internal server error, I installed fiddler and saw 401, unauthorized before internal server error.

Reply
Temmy Raharjo responded on 15 Jul 2018 12:59 AM
My Badges
Suggested Answer

Hi,

I never try that code, but usually if I need to have function for that one. I used third party library like XrmServiceToolkit. You just to add the library on the form.

crm2011and2013solutions.blogspot.com/.../change-status-using-javascript.html

Reply
Sandeep Mishra responded on 15 Jul 2018 6:46 AM
My Badges
Suggested Answer

Hi,

Use this -

Guid EntityID = new Guid("Entity ID");

SetStateRequest request = new SetStateRequest

{

   EntityMoniker = new EntityReference("EntityName", EntityID),

   State = new OptionSetValue(2),

   Status = new OptionSetValue(3)

};

_sdk.Execute(request);

Reply
Albert_ responded on 15 Jul 2018 7:25 AM
My Badges

I have CRM 2011 on-permise   :-)

Reply
Albert_ responded on 15 Jul 2018 8:09 AM
My Badges

Now it gives me error 500 inernal state, I have edited the question and post the fiddler output.

Reply
Radu Chiribelea responded on 16 Jul 2018 6:06 AM
My Badges

Can you please also collect a CRM Platform trace and paste here the exception with the call stack?

Reply
Albert_ responded on 20 Jul 2018 1:54 AM
My Badges

My purpose by this post was to change status and statusreason that i did that via this question,

I found my answer and I did reply that.

Here is the link :

community.dynamics.com/.../826127

Reply
Temmy Raharjo responded on 15 Jul 2018 12:59 AM
My Badges
Suggested Answer

Hi,

I never try that code, but usually if I need to have function for that one. I used third party library like XrmServiceToolkit. You just to add the library on the form.

crm2011and2013solutions.blogspot.com/.../change-status-using-javascript.html

Reply
Sandeep Mishra responded on 15 Jul 2018 6:46 AM
My Badges
Suggested Answer

Hi,

Use this -

Guid EntityID = new Guid("Entity ID");

SetStateRequest request = new SetStateRequest

{

   EntityMoniker = new EntityReference("EntityName", EntityID),

   State = new OptionSetValue(2),

   Status = new OptionSetValue(3)

};

_sdk.Execute(request);

Reply

SBX - Two Col Forum

SBX - Migrated JS