Friday, 28 November 2014

Script to Update the Servive Request in CRM

DECLARE
l_return_status              VARCHAR2(1);
l_msg_count                  NUMBER;
l_msg_data                   VARCHAR2(1000);
l_msg_dummy                  VARCHAR2 (4000) ;
l_output                     VARCHAR2 (15000);
l_last_update_date           DATE   := SYSDATE ;
l_service_request_rec        cs_servicerequest_pub.service_request_rec_type;
l_notes                      cs_servicerequest_pub.notes_table;
l_contacts                   cs_servicerequest_pub.contacts_table;
l_sr_update_out_rec          cs_servicerequest_pub.sr_update_out_rec_type;
l_workflow_process_id       NUMBER;
l_interaction_id            NUMBER;
l_user_id                   NUMBER;
l_resp_id                   NUMBER;
l_resp_appl_id              NUMBER;
BEGIN
   BEGIN
      SELECT user_id
      INTO l_user_id
      FROM fnd_user
      WHERE user_name = 'CONVERSION';
   EXCEPTION
     WHEN OTHERS THEN
       l_user_id := NULL;
   END;
  
   BEGIN
      SELECT responsibility_id, application_id
      INTO l_resp_id, l_resp_appl_id
      FROM fnd_responsibility_vl
      WHERE responsibility_name = 'Customer Support';
   EXCEPTION
     WHEN OTHERS THEN
       l_resp_id       := NULL;
       l_resp_appl_id  := NULL;
   END;

fnd_global.apps_initialize (l_user_id, l_resp_id, l_resp_appl_id);
MO_GLOBAL.INIT ('CS');
cs_servicerequest_pub.initialize_rec( l_service_request_rec);
l_service_request_rec.request_attribute_8 := 'Y';
CS_ServiceRequest_PUB.Update_ServiceRequest (p_api_version            => 3.0,
                                             p_init_msg_list          => FND_API.G_FALSE,
                                             p_commit                 => FND_API.G_FALSE,
                                             x_return_status          => l_return_status,
                                             x_msg_count              => l_msg_count,
                                             x_msg_data               => l_msg_data,
                                             p_request_id             => &incident_id,
                                             p_request_number         => NULL,
                                             p_audit_comments         => NULL,
                                             p_object_version_number  => &object_version_number,
                                             p_resp_appl_id           => NULL,                                                                                                                                                                                                                                         --fnd_global.resp_appl_id,
                                             p_resp_id                => NULL,                                                                                                                                                                                                                                                                                           --fnd_global.resp_id,
                                             p_last_updated_by        => NULL,                                                                                                                                                                                                                                                                                   --fnd_global.user_id,
                                             p_last_update_login      => NULL,
                                             p_workflow_process_id    => NULL,
                                             p_last_update_date       => l_last_update_date,
                                             p_service_request_rec    => l_service_request_rec,
                                             p_notes                  => l_notes,
                                             p_contacts               => l_contacts,
                                             p_called_by_workflow     => FND_API.G_FALSE,
                                             x_workflow_process_id    => l_workflow_process_id,
                                             x_interaction_id         => l_interaction_id );
      IF (l_return_status = 'S') then
        COMMIT;
      ELSE
        ROLLBACK;
         BEGIN
           FOR i IN 1 .. l_msg_count
           LOOP
               fnd_msg_pub.get (i,
                                fnd_api.g_false,
                                l_msg_data,
                                l_msg_dummy);
                l_output := (TO_CHAR (i) || ': ' || l_msg_data);
           END LOOP;
         END;
               DBMS_OUTPUT.PUT_LINE ('Error :'||l_output);
       END IF;
    DBMS_OUTPUT.PUT_LINE ('Status :'||l_return_status);
END;
/

No comments:

Post a Comment