📜 ⬆️ ⬇️

Integration of 1C and Megaplan or why web services are good

Habré already has many articles about 1C and its “bad” ability to integrate with other systems. And I agree with them, integrating 1C and Megaplan turned out to be a task, far less pleasant than I assumed at the beginning.

In the article I will not tell you how to get and set up synchronization through the API using a web service from start to finish. But I’ll tell you the key moments after which finding the missing information is not a problem.

Prehistory

I got into the 1C department in which there was my own, written by employees, configuration for receiving and managing tasks “PM”. As time went on, the configuration developed and overgrown with new functionality, and it was no longer possible to abandon it, since it became a single center for receiving and processing tasks, not only of the 1C department, but of all IT departments of the holding (at the time of writing this article, Administrative and economic department and building management department). The configuration was configured to synchronize with LDAP, all holding databases, automatic notifications via skype, and more.

Story

A deputy technical director was taken, who painted the advantages of Megaplana in paints and convinced the management that it was vital for us to implement it. After lengthy explanations that we could not refuse “RM”, I was given the task to synchronize our configuration and Megaplan. Armed with the lion's share of patience, I began to explore the possibilities and immediately realized that Megaplana has only an API and I need to dig there. After several days of searching and experimenting, it was clear that only 1C means could not do this.
')
This is where the explanation of why web services start is good.

Unfortunately, we already had one web server configured, to which I connected my web service. For this reason, the setting of the web server itself, I can not tell.

Setup part 1: Configure the web service part.

Thanks Megaplan, there are api libraries and even everyone works, so all we need to do is configure only the data models. As an example, add a comment.

We describe the method we will call from 1C

/** * Marks comment as read * * @access public * @param object $data * @return array */ public function comment_create($data) { $options = array( 'method' => 'post', 'useHttps' => true, ); return $this->send_request(__FUNCTION__, $data, $options); } 


We describe the model of the method

  require APPPATH.'controllers/common/common_types.php'; $types = array_merge_recursive( $types, array( // api methods 'methods' => array ( 'comment_create' => array( 'type' => 'public', 'returnType' => 'CommentEditReturn', 'description' => 'create comment', 'params' => array( 'data' => array( 'varName' => '$data', 'varType' => 'CommentEditInput', ), ) ), ), // api custom types for api methods 'types' => array( 'CommentCreateModel' => array( 'Text' => 'string', 'Work' => 'int', 'WorkDate' => 'string', 'Attaches' => 'CommentAttachment[]', ), 'CommentAttachment' => array( 'Add' => 'CommentAttachmentItem[]', ), 'CommentAttachmentItem' => array( 'Name' => 'string', 'Context' => 'string', ), ), ) ); 


Next, let's say your web service is visible at your domain / api / comments / get_wsdl, and when you go, you see XML describing your web service.

Setup part 2: Setup 1C part.

Then we add a web service to our configuration, we open, we look and indeed all the methods that we described are and have not gone away. I certainly have more method.


And finally, the most fascinating we write code on 1C.

 //   (,,=,=)   =.;  = .(.,.,"");  .status.code = "ok"   = WS.WSMegaPlanComments.WS("urn:comments","commentsService","commentsPort");  = .XDTO.(.XDTO.("urn:comments", "CommentEditInput")); .AccessId = .data.AccessId; .SecretKey = .data.SecretKey; .SubjectType="task"; .SubjectId=((),"=0");  = .XDTO.(.XDTO.("urn:comments", "CommentCreateModel")); .Text= XML(); .Work=; .WorkDate=(,"='dd.MM.yyyy hh:mm:ss'"); .Model=;  = .comment_create();  ;   " :     ."; ;   " :"+ . + (); ;  //  (, , )    = WS.WSMegaPlanTasks.WS("urn:tasks","tasksService","tasksPort");  = .XDTO.(.XDTO.("urn:tasks", "AuthorizationData")); .Login = ;  = ""; md5(, ); .Password = ; .OneTimeKey = ;  .authorize();   = ();  " :"+ . + .; ;  


Actually everything. Now it remains only to fasten the function call where you need it and that's it. Megaplan gets our comments from 1C.

Source: https://habr.com/ru/post/179241/


All Articles